@@ -1610,10 +1610,80 @@ handler_id
1610
1610
1611
1611
**type **: ``string `` **default **: ``session.handler.native_file ``
1612
1612
1613
- The service id used for session storage. The default value ``'session.handler.native_file' ``
1613
+ The service id or DSN used for session storage. The default value ``'session.handler.native_file' ``
1614
1614
will let Symfony manage the sessions itself using files to store the session metadata.
1615
1615
Set it to ``null `` to use the native PHP session mechanism.
1616
- You can also :ref: `store sessions in a database <session-database >`.
1616
+ It is possible to :ref: `store sessions in a database <session-database >`,
1617
+ and also to configure the session handler with a DSN:
1618
+
1619
+ .. configuration-block ::
1620
+
1621
+ .. code-block :: yaml
1622
+
1623
+ # config/packages/framework.yaml
1624
+ framework :
1625
+ session :
1626
+ # a few possible examples
1627
+ handler_id : ' redis://localhost'
1628
+ handler_id : ' %env(REDIS_URL)%'
1629
+ handler_id : ' %env(DATABASE_URL)%'
1630
+ handler_id : ' file://%kernel.project_dir%/var/sessions'
1631
+
1632
+ .. code-block :: xml
1633
+
1634
+ <!-- config/packages/framework.xml -->
1635
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
1636
+ <container xmlns =" http://symfony.com/schema/dic/services"
1637
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
1638
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
1639
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
1640
+ https://symfony.com/schema/dic/services/services-1.0.xsd
1641
+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
1642
+ <framework : config >
1643
+ <!-- a few possible examples -->
1644
+ <framework : session enabled =" true"
1645
+ handler-id =" redis://localhost"
1646
+ handler-id =" %env(REDIS_URL)%"
1647
+ handler-id =" %env(DATABASE_URL)%"
1648
+ handler-id =" file://%kernel.project_dir%/var/sessions" />
1649
+ </framework : config >
1650
+ </container >
1651
+
1652
+ .. code-block :: php
1653
+
1654
+ // config/packages/framework.php
1655
+ use function Symfony\Component\DependencyInjection\Loader\Configurator\env;
1656
+ use Symfony\Config\FrameworkConfig;
1657
+
1658
+ return static function (FrameworkConfig $framework): void {
1659
+ // ...
1660
+
1661
+ $framework->session()
1662
+ // a few possible examples
1663
+ ->handlerId('redis://localhost')
1664
+ ->handlerId(env('REDIS_URL'))
1665
+ ->handlerId(env('DATABASE_URL'))
1666
+ ->handlerId('file://%kernel.project_dir%/var/sessions');
1667
+ };
1668
+
1669
+ .. note ::
1670
+
1671
+ Supported DSN protocols are the following:
1672
+
1673
+ * ``file ``
1674
+ * ``redis ``
1675
+ * ``rediss `` (Redis over TLS)
1676
+ * ``memcached `` (requires :doc: `symfony/cache </components/cache >`)
1677
+ * ``pdo_oci `` (requires :doc: `doctrine/dbal </doctrine/dbal >`)
1678
+ * ``mssql ``
1679
+ * ``mysql ``
1680
+ * ``mysql2 ``
1681
+ * ``pgsql ``
1682
+ * ``postgres ``
1683
+ * ``postgresql ``
1684
+ * ``sqlsrv ``
1685
+ * ``sqlite ``
1686
+ * ``sqlite3 ``
1617
1687
1618
1688
.. _name :
1619
1689
0 commit comments