Skip to content

Commit 264ebcc

Browse files
[FrameworkBundle] Add documentation about using a DSN as the session.handler_id
1 parent e886b53 commit 264ebcc

File tree

1 file changed

+72
-2
lines changed

1 file changed

+72
-2
lines changed

reference/configuration/framework.rst

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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'``
16121612
will let Symfony manage the sessions itself using files to store the session metadata.
16131613
Set 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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy