Skip to content

Commit f094237

Browse files
committed
[#3276] Trying to further clarify the session storage directory details
1 parent beb3ba3 commit f094237

File tree

1 file changed

+74
-13
lines changed

1 file changed

+74
-13
lines changed

cookbook/session/sessions_directory.rst

+74-13
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,84 @@
44
Configuring the Directory Where Sessions Files are Saved
55
========================================================
66

7-
By default, Symfony stores the session data in files in the cache
8-
directory ``%kernel.cache_dir%/sessions``. This means that when you clear
9-
the cache, any current sessions will also be deleted.
7+
By default, the Symfony Standard Edition uses the global ``php.ini`` values
8+
for ``session.save_handler`` and ``session.save_path`` to determine where
9+
to store session data. This is because of the following configuration:
1010

11-
.. note::
11+
.. configuration-block::
12+
13+
.. code-block:: yaml
14+
15+
# app/config/config.yml
16+
framework:
17+
session:
18+
# handler_id set to null will use default session handler from php.ini
19+
handler_id: ~
20+
21+
.. code-block:: xml
22+
23+
<!-- app/config/config.xml -->
24+
<?xml version="1.0" encoding="UTF-8" ?>
25+
<container xmlns="http://symfony.com/schema/dic/services"
26+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
27+
xmlns:framework="http://symfony.com/schema/dic/symfony"
28+
xsi:schemaLocation="http://symfony.com/schema/dic/services
29+
http://symfony.com/schema/dic/services/services-1.0.xsd
30+
http://symfony.com/schema/dic/symfony
31+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
32+
>
33+
<framework:config>
34+
<framework:session handler-id="null" />
35+
</framework:config>
36+
</container>
1237
13-
If the ``session`` configuration key is set to ``~``, Symfony will use the
14-
global PHP ini values for ``session.save_handler`` and associated
15-
``session.save_path`` from ``php.ini``.
38+
.. code-block:: php
39+
40+
// app/config/config.php
41+
$container->loadFromExtension('framework', array(
42+
'session' => array(
43+
'handler-id' => null,
44+
),
45+
));
1646
17-
.. note::
47+
With this configuration, changing *where* your session metadata is stored
48+
is entirely up to your ``php.ini`` configuration.
1849

19-
While the Symfony Full Stack Framework defaults to using the
20-
``session.handler.native_file``, the Symfony Standard Edition is
21-
configured to use PHP's global session settings by default and therefor
22-
sessions will be stored according to the ``session.save_path`` location
23-
and will not be deleted when clearing the cache.
50+
However, if you have the following configuration, Symfony will store the session
51+
data in files in the cache directory ``%kernel.cache_dir%/sessions``. This
52+
means that when you clear the cache, any current sessions will also be deleted:
53+
54+
.. configuration-block::
55+
56+
.. code-block:: yaml
57+
58+
# app/config/config.yml
59+
framework:
60+
session: ~
61+
62+
.. code-block:: xml
63+
64+
<!-- app/config/config.xml -->
65+
<?xml version="1.0" encoding="UTF-8" ?>
66+
<container xmlns="http://symfony.com/schema/dic/services"
67+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
68+
xmlns:framework="http://symfony.com/schema/dic/symfony"
69+
xsi:schemaLocation="http://symfony.com/schema/dic/services
70+
http://symfony.com/schema/dic/services/services-1.0.xsd
71+
http://symfony.com/schema/dic/symfony
72+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
73+
>
74+
<framework:config>
75+
<framework:session />
76+
</framework:config>
77+
</container>
78+
79+
.. code-block:: php
80+
81+
// app/config/config.php
82+
$container->loadFromExtension('framework', array(
83+
'session' => array(),
84+
));
2485
2586
Using a different directory to save session data is one method to ensure
2687
that your current sessions aren't lost when you clear Symfony's cache.

0 commit comments

Comments
 (0)