-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[FrameworkBundle] Add documentation about using a DSN as the session.handler_id
#15560
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1364,10 +1364,45 @@ 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 :doc:`store sessions in a database </session/database>`. | ||||||||||
Set it to ``null`` to use the native PHP session mechanism. You can also provide a DSN to specify | ||||||||||
the used storage-directory or :doc:`store sessions in a database </session/database>`: | ||||||||||
|
||||||||||
.. configuration-block:: | ||||||||||
|
||||||||||
.. code-block:: yaml | ||||||||||
|
||||||||||
# config/packages/framework.yaml | ||||||||||
framework: | ||||||||||
session: | ||||||||||
# ... | ||||||||||
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="file://%kernel.project_dir%/var/sessions"/> | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
</framework:config> | ||||||||||
</container> | ||||||||||
|
||||||||||
.. code-block:: php | ||||||||||
|
||||||||||
// config/packages/framework.php | ||||||||||
$container->loadFromExtension('framework', [ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use the container configurator as done in other config blocks. |
||||||||||
'session' => [ | ||||||||||
// ... | ||||||||||
'handler_id' => 'file://%kernel.project_dir%/var/sessions', | ||||||||||
], | ||||||||||
]); | ||||||||||
|
||||||||||
.. _name: | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,64 @@ across different servers. | |
Symfony can store sessions in all kinds of databases (relational, NoSQL and | ||
key-value) but recommends key-value databases like Redis to get best performance. | ||
|
||
Define Session Storage by DSN | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given my comment above this section should not be necessary. |
||
----------------------------- | ||
|
||
Besides specifying a service as the session-handler you can also provide a | ||
"DSN" directly and let Symfony create the necessary services/clients: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# config/packages/framework.yaml | ||
framework: | ||
session: | ||
# ... | ||
handler_id: 'redis://password@redis-server:6379' | ||
|
||
.. 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://password@redis-server:6379"/> | ||
</framework:config> | ||
</container> | ||
|
||
.. code-block:: php | ||
|
||
// config/packages/framework.php | ||
$container->loadFromExtension('framework', [ | ||
'session' => [ | ||
// ... | ||
'handler_id' => 'redis://password@redis-server:6379', | ||
], | ||
]); | ||
|
||
Supported DSN protocols are: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move this part in a |
||
|
||
- file (i.e.: ``file://%kernel.project_dir%/var/sessions``) | ||
- redis (i.e.: ``redis://redis-server:6379``) | ||
- rediss | ||
- memcached | ||
- pdo_oci | ||
- mssql | ||
- mysql | ||
- mysql2 | ||
- pgsql | ||
- postgres | ||
- postgresql | ||
- sqlsrv | ||
- sqlite | ||
- sqlite3 | ||
|
||
Store Sessions in a key-value Database (Redis) | ||
---------------------------------------------- | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding more examples as it was done in https://github.com/symfony/symfony-docs/pull/13227/files#diff-278a8e1908e2f0de9f2753d344b248e41eebde795a8e340569d2d0a3514cb29eR1290?