Skip to content

[FrameworkBundle] Add documentation about using a DSN as the session.handler_id #18767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 72 additions & 2 deletions reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1608,10 +1608,80 @@ handler_id

**type**: ``string`` **default**: ``session.handler.native_file``

The service id used for session storage. The default value ``'session.handler.native_file'``
The service id or DSN used for session storage. The default value ``'session.handler.native_file'``
will let Symfony manage the sessions itself using files to store the session metadata.
Set it to ``null`` to use the native PHP session mechanism.
You can also :ref:`store sessions in a database <session-database>`.
It is possible to :ref:`store sessions in a database <session-database>`,
and also to configure the session handler with a DSN:

.. configuration-block::

.. code-block:: yaml

# config/packages/framework.yaml
framework:
session:
# a few possible examples
handler_id: 'redis://localhost'
handler_id: '%env(REDIS_URL)%'
handler_id: '%env(DATABASE_URL)%'
handler_id: 'file://%kernel.project_dir%/var/sessions'

.. code-block:: xml

<!-- config/packages/framework.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<!-- a few possible examples -->
<framework:session enabled="true"
handler-id="redis://localhost"
handler-id="%env(REDIS_URL)%"
handler-id="%env(DATABASE_URL)%"
handler-id="file://%kernel.project_dir%/var/sessions"/>
</framework:config>
</container>

.. code-block:: php

// config/packages/framework.php
use function Symfony\Component\DependencyInjection\Loader\Configurator\env;
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework): void {
// ...

$framework->session()
// a few possible examples
->handlerId('redis://localhost')
->handlerId(env('REDIS_URL'))
->handlerId(env('DATABASE_URL'))
->handlerId('file://%kernel.project_dir%/var/sessions');
};

.. note::

Supported DSN protocols are the following:

* ``file``
* ``redis``
* ``rediss`` (Redis over TLS)
* ``memcached`` (requires :doc:`symfony/cache </components/cache>`)
* ``pdo_oci`` (requires :doc:`doctrine/dbal </doctrine/dbal>`)
* ``mssql``
* ``mysql``
* ``mysql2``
* ``pgsql``
* ``postgres``
* ``postgresql``
* ``sqlsrv``
* ``sqlite``
* ``sqlite3``

.. _name:

Expand Down
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