@@ -1643,10 +1643,80 @@ handler_id
16431643
16441644**type **: ``string `` **default **: ``session.handler.native_file ``
16451645
1646- The service id used for session storage. The default value ``'session.handler.native_file' ``
1646+ The service id or DSN used for session storage. The default value ``'session.handler.native_file' ``
16471647will let Symfony manage the sessions itself using files to store the session metadata.
16481648Set it to ``null `` to use the native PHP session mechanism.
1649- You can also :ref: `store sessions in a database <session-database >`.
1649+ It is possible to :ref: `store sessions in a database <session-database >`,
1650+ and also to configure the session handler with a DSN:
1651+
1652+ .. configuration-block ::
1653+
1654+ .. code-block :: yaml
1655+
1656+ # config/packages/framework.yaml
1657+ framework :
1658+ session :
1659+ # a few possible examples
1660+ handler_id : ' redis://localhost'
1661+ handler_id : ' %env(REDIS_URL)%'
1662+ handler_id : ' %env(DATABASE_URL)%'
1663+ handler_id : ' file://%kernel.project_dir%/var/sessions'
1664+
1665+ .. code-block :: xml
1666+
1667+ <!-- config/packages/framework.xml -->
1668+ <?xml version =" 1.0" encoding =" UTF-8" ?>
1669+ <container xmlns =" http://symfony.com/schema/dic/services"
1670+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
1671+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
1672+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
1673+ https://symfony.com/schema/dic/services/services-1.0.xsd
1674+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
1675+ <framework : config >
1676+ <!-- a few possible examples -->
1677+ <framework : session enabled =" true"
1678+ handler-id =" redis://localhost"
1679+ handler-id =" %env(REDIS_URL)%"
1680+ handler-id =" %env(DATABASE_URL)%"
1681+ handler-id =" file://%kernel.project_dir%/var/sessions" />
1682+ </framework : config >
1683+ </container >
1684+
1685+ .. code-block :: php
1686+
1687+ // config/packages/framework.php
1688+ use function Symfony\Component\DependencyInjection\Loader\Configurator\env;
1689+ use Symfony\Config\FrameworkConfig;
1690+
1691+ return static function (FrameworkConfig $framework): void {
1692+ // ...
1693+
1694+ $framework->session()
1695+ // a few possible examples
1696+ ->handlerId('redis://localhost')
1697+ ->handlerId(env('REDIS_URL'))
1698+ ->handlerId(env('DATABASE_URL'))
1699+ ->handlerId('file://%kernel.project_dir%/var/sessions');
1700+ };
1701+
1702+ .. note ::
1703+
1704+ Supported DSN protocols are the following:
1705+
1706+ * ``file ``
1707+ * ``redis ``
1708+ * ``rediss `` (Redis over TLS)
1709+ * ``memcached `` (requires :doc: `symfony/cache </components/cache >`)
1710+ * ``pdo_oci `` (requires :doc: `doctrine/dbal </doctrine/dbal >`)
1711+ * ``mssql ``
1712+ * ``mysql ``
1713+ * ``mysql2 ``
1714+ * ``pgsql ``
1715+ * ``postgres ``
1716+ * ``postgresql ``
1717+ * ``sqlsrv ``
1718+ * ``sqlite ``
1719+ * ``sqlite3 ``
16501720
16511721.. _name :
16521722
0 commit comments