Skip to content

Commit 32f376d

Browse files
fabpotwouterj
andcommitted
Update session.rst
Co-authored-by: Wouter de Jong <[email protected]>
1 parent a57de8c commit 32f376d

File tree

2 files changed

+81
-40
lines changed

2 files changed

+81
-40
lines changed

_build/redirection_map

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@
248248
/cookbook/session/index /session
249249
/cookbook/session/limit_metadata_writes /reference/configuration/framework
250250
/session/limit_metadata_writes /reference/configuration/framework
251-
/cookbook/session/locale_sticky_session /session
252-
/cookbook/locale_sticky_session /session
251+
/cookbook/session/locale_sticky_session /session#locale-sticky-session
252+
/cookbook/locale_sticky_session /session#locale-sticky-session
253253
/cookbook/session/php_bridge /session/php_bridge
254254
/cookbook/session/proxy_examples /session/proxy_examples
255255
/cookbook/session/sessions_directory /session/sessions_directory
@@ -478,9 +478,9 @@
478478
/components/translation/custom_message_formatter https://github.com/symfony/translation
479479
/components/notifier https://github.com/symfony/notifier
480480
/components/routing https://github.com/symfony/routing
481-
/session/database /session
482-
/doctrine/pdo_session_storage /session
483-
/doctrine/mongodb_session_storage /session
481+
/session/database /session#session-database
482+
/doctrine/pdo_session_storage /session#session-database-pdo
483+
/doctrine/mongodb_session_storage /session#session-database-mongodb
484484
/components/dotenv https://github.com/symfony/dotenv
485485
/components/mercure /mercure
486486
/components/polyfill_apcu https://github.com/symfony/polyfill-apcu

session.rst

Lines changed: 76 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ subsystem which is designed to provide session management that you can use to
1313
store information about the user between requests through a clear
1414
object-oriented interface using a variety of session storage drivers.
1515

16-
You need to install HttpFoundation to handle sessions:
16+
You need to install the HttpFoundation component to handle sessions:
1717

1818
.. code-block:: terminal
1919
@@ -101,9 +101,9 @@ From a Symfony controller, type-hint an argument with
101101
Attributes
102102
----------
103103

104-
PHP's session management requires the use of the ``$_SESSION`` super-global,
105-
however, this interferes somewhat with code testability and encapsulation in an
106-
OOP paradigm. To help overcome this, Symfony uses *session bags* linked to the
104+
PHP's session management requires the use of the ``$_SESSION`` super-global.
105+
However, this interferes with code testability and encapsulation in an OOP
106+
paradigm. To help overcome this, Symfony uses *session bags* linked to the
107107
session to encapsulate a specific dataset of **attributes**.
108108

109109
This approach mitigates namespace pollution within the ``$_SESSION``
@@ -466,18 +466,17 @@ installed and configured the `phpredis extension`_.
466466

467467
You have two different options to use Redis to store sessions:
468468

469-
(1) The first PHP-based option is to configure Redis session handler directly
470-
in the server ``php.ini`` file:
469+
The first PHP-based option is to configure Redis session handler directly
470+
in the server ``php.ini`` file:
471471

472472
.. code-block:: ini
473473
474474
; php.ini
475475
session.save_handler = redis
476476
session.save_path = "tcp://192.168.0.178:6379?auth=REDIS_PASSWORD"
477477
478-
(2) The second Symfony-based option is to configure Redis sessions as follows.
479-
480-
First, define a Symfony service for the connection to the Redis server:
478+
The second option is to configure Redis sessions in Symfony. First, define
479+
a Symfony service for the connection to the Redis server:
481480

482481
.. configuration-block::
483482

@@ -567,18 +566,26 @@ and ``RedisProxy``:
567566
.. code-block:: xml
568567
569568
<!-- config/services.xml -->
570-
<services>
571-
<service id="Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler">
572-
<argument type="service" id="Redis"/>
573-
<!-- you can optionally pass an array of options. The only options are 'prefix' and 'ttl',
574-
which define the prefix to use for the keys to avoid collision on the Redis server
575-
and the expiration time for any given entry (in seconds), defaults are 'sf_s' and null:
576-
<argument type="collection">
577-
<argument key="prefix">my_prefix</argument>
578-
<argument key="ttl">600</argument>
579-
</argument> -->
580-
</service>
581-
</services>
569+
<!-- config/services.xml -->
570+
<?xml version="1.0" encoding="UTF-8" ?>
571+
<container xmlns="http://symfony.com/schema/dic/services"
572+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
573+
xsi:schemaLocation="http://symfony.com/schema/dic/services
574+
https://symfony.com/schema/dic/services/services-1.0.xsd">
575+
576+
<services>
577+
<service id="Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler">
578+
<argument type="service" id="Redis"/>
579+
<!-- you can optionally pass an array of options. The only options are 'prefix' and 'ttl',
580+
which define the prefix to use for the keys to avoid collision on the Redis server
581+
and the expiration time for any given entry (in seconds), defaults are 'sf_s' and null:
582+
<argument type="collection">
583+
<argument key="prefix">my_prefix</argument>
584+
<argument key="ttl">600</argument>
585+
</argument> -->
586+
</service>
587+
</services>
588+
</container>
582589
583590
.. code-block:: php
584591
@@ -612,10 +619,20 @@ configuration option to tell Symfony to use this service as the session handler:
612619
.. code-block:: xml
613620
614621
<!-- config/packages/framework.xml -->
615-
<framework:config>
616-
<!-- ... -->
617-
<framework:session handler-id="Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler"/>
618-
</framework:config>
622+
<?xml version="1.0" encoding="UTF-8" ?>
623+
<container xmlns="http://symfony.com/schema/dic/services"
624+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
625+
xmlns:framework="http://symfony.com/schema/dic/symfony"
626+
xsi:schemaLocation="http://symfony.com/schema/dic/services
627+
https://symfony.com/schema/dic/services/services-1.0.xsd
628+
http://symfony.com/schema/dic/symfony
629+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
630+
631+
<framework:config>
632+
<!-- ... -->
633+
<framework:session handler-id="Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler"/>
634+
</framework:config>
635+
</container>
619636
620637
.. code-block:: php
621638
@@ -642,6 +659,8 @@ and only the first one stored the CSRF token in the session.
642659
replace ``RedisSessionHandler`` by
643660
:class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\MemcachedSessionHandler`.
644661

662+
.. _session-database-pdo:
663+
645664
Store Sessions in a Relational Database (MariaDB, MySQL, PostgreSQL)
646665
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
647666

@@ -737,11 +756,21 @@ configuration option to tell Symfony to use this service as the session handler:
737756
.. code-block:: xml
738757
739758
<!-- config/packages/framework.xml -->
740-
<framework:config>
741-
<!-- ... -->
742-
<framework:session
743-
handler-id="Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler"/>
744-
</framework:config>
759+
<?xml version="1.0" encoding="UTF-8" ?>
760+
<container xmlns="http://symfony.com/schema/dic/services"
761+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
762+
xmlns:framework="http://symfony.com/schema/dic/symfony"
763+
xsi:schemaLocation="http://symfony.com/schema/dic/services
764+
https://symfony.com/schema/dic/services/services-1.0.xsd
765+
http://symfony.com/schema/dic/symfony
766+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
767+
768+
<framework:config>
769+
<!-- ... -->
770+
<framework:session
771+
handler-id="Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler"/>
772+
</framework:config>
773+
</container>
745774
746775
.. code-block:: php
747776
@@ -925,6 +954,8 @@ Microsoft SQL Server
925954
INDEX sessions_sess_lifetime_idx (sess_lifetime)
926955
);
927956
957+
.. _session-database-mongodb:
958+
928959
Store Sessions in a NoSQL Database (MongoDB)
929960
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
930961

@@ -1000,11 +1031,21 @@ configuration option to tell Symfony to use this service as the session handler:
10001031
.. code-block:: xml
10011032
10021033
<!-- config/packages/framework.xml -->
1003-
<framework:config>
1004-
<!-- ... -->
1005-
<framework:session
1006-
handler-id="Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler"/>
1007-
</framework:config>
1034+
<?xml version="1.0" encoding="UTF-8" ?>
1035+
<container xmlns="http://symfony.com/schema/dic/services"
1036+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1037+
xmlns:framework="http://symfony.com/schema/dic/symfony"
1038+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1039+
https://symfony.com/schema/dic/services/services-1.0.xsd
1040+
http://symfony.com/schema/dic/symfony
1041+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
1042+
1043+
<framework:config>
1044+
<!-- ... -->
1045+
<framework:session
1046+
handler-id="Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler"/>
1047+
</framework:config>
1048+
</container>
10081049
10091050
.. code-block:: php
10101051

0 commit comments

Comments
 (0)