Skip to content

[HttpFoundation] Allow to configure session handlers with DSN #13227

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
Mar 6, 2020
Merged
Show file tree
Hide file tree
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
52 changes: 52 additions & 0 deletions reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,58 @@ the native PHP session mechanism. Set it to ``'session.handler.native_file'`` to
let Symfony manage the sessions itself using files to store the session
metadata.

You can also configure the session handler with a DSN. For example:

.. configuration-block::

.. code-block:: yaml

# config/packages/framework.yaml
framework:
session:
# ...
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>
<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
$container->loadFromExtension('framework', [
'session' => [
// ...
'handler_id' => 'redis://localhost',
'handler_id' => '%env(REDIS_URL)%',
'handler_id' => '%env(DATABASE_URL)%',
'handler_id' => 'file://%kernel.project_dir%/var/sessions',
],
]);

.. versionadded:: 4.4

The option to configure the session handler with a DSN was introduced in Symfony 4.4.

If you prefer to make Symfony store sessions in a database read
:doc:`/doctrine/pdo_session_storage`.

Expand Down
6 changes: 3 additions & 3 deletions session.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sessions, check their default configuration:
# enables the support of sessions in the app
enabled: true
# ID of the service used for session storage.
# NULL = means that PHP's default session mechanism is used
# NULL means that Symfony uses PHP default session mechanism
handler_id: null
# improves the security of the cookies used for sessions
cookie_secure: 'auto'
Expand All @@ -42,7 +42,7 @@ sessions, check their default configuration:
<!--
enabled: enables the support of sessions in the app
handler-id: ID of the service used for session storage
NULL means that PHP's default session mechanism is used
NULL means that Symfony uses PHP default session mechanism
cookie-secure and cookie-samesite: improves the security of the cookies used for sessions
-->
<framework:session enabled="true"
Expand All @@ -60,7 +60,7 @@ sessions, check their default configuration:
// enables the support of sessions in the app
'enabled' => true,
// ID of the service used for session storage
// NULL means that PHP's default session mechanism is used
// NULL means that Symfony uses PHP default session mechanism
'handler_id' => null,
// improves the security of the cookies used for sessions
'cookie_secure' => 'auto',
Expand Down