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