@@ -13,7 +13,7 @@ subsystem which is designed to provide session management that you can use to
13
13
store information about the user between requests through a clear
14
14
object-oriented interface using a variety of session storage drivers.
15
15
16
- You need to install HttpFoundation to handle sessions:
16
+ You need to install the HttpFoundation component to handle sessions:
17
17
18
18
.. code-block :: terminal
19
19
@@ -101,9 +101,9 @@ From a Symfony controller, type-hint an argument with
101
101
Attributes
102
102
----------
103
103
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
107
107
session to encapsulate a specific dataset of **attributes **.
108
108
109
109
This approach mitigates namespace pollution within the ``$_SESSION ``
@@ -466,18 +466,17 @@ installed and configured the `phpredis extension`_.
466
466
467
467
You have two different options to use Redis to store sessions:
468
468
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:
471
471
472
472
.. code-block :: ini
473
473
474
474
; php.ini
475
475
session.save_handler = redis
476
476
session.save_path = " tcp://192.168.0.178:6379?auth=REDIS_PASSWORD"
477
477
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:
481
480
482
481
.. configuration-block ::
483
482
@@ -567,18 +566,26 @@ and ``RedisProxy``:
567
566
.. code-block :: xml
568
567
569
568
<!-- 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 >
582
589
583
590
.. code-block :: php
584
591
@@ -612,10 +619,20 @@ configuration option to tell Symfony to use this service as the session handler:
612
619
.. code-block :: xml
613
620
614
621
<!-- 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 >
619
636
620
637
.. code-block :: php
621
638
@@ -642,6 +659,8 @@ and only the first one stored the CSRF token in the session.
642
659
replace ``RedisSessionHandler `` by
643
660
:class: `Symfony\\ Component\\ HttpFoundation\\ Session\\ Storage\\ Handler\\ MemcachedSessionHandler `.
644
661
662
+ .. _session-database-pdo :
663
+
645
664
Store Sessions in a Relational Database (MariaDB, MySQL, PostgreSQL)
646
665
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
647
666
@@ -737,11 +756,21 @@ configuration option to tell Symfony to use this service as the session handler:
737
756
.. code-block :: xml
738
757
739
758
<!-- 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 >
745
774
746
775
.. code-block :: php
747
776
@@ -925,6 +954,8 @@ Microsoft SQL Server
925
954
INDEX sessions_sess_lifetime_idx (sess_lifetime)
926
955
);
927
956
957
+ .. _session-database-mongodb :
958
+
928
959
Store Sessions in a NoSQL Database (MongoDB)
929
960
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
930
961
@@ -1000,11 +1031,21 @@ configuration option to tell Symfony to use this service as the session handler:
1000
1031
.. code-block :: xml
1001
1032
1002
1033
<!-- 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 >
1008
1049
1009
1050
.. code-block :: php
1010
1051
0 commit comments