Skip to content

Commit 72b53ad

Browse files
committed
minor #3404 [#3276] Trying to further clarify the session storage directory details (weaverryan)
This PR was merged into the 2.3 branch. Discussion ---------- [#3276] Trying to further clarify the session storage directory details Hi guys! This continues after #3342. Basically, it's confusing the symfony/symfony has a different default than the Symfony SE. However, I agree with Wouter that most framework readers are probably SE users. My strategy is simply to show people which configuration causes which situation. | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | all (or 2.3+) | Fixed tickets | #3276 Thanks! Commits ------- adc57be [#3404] Adding a few comments, per @wouterj f094237 [#3276] Trying to further clarify the session storage directory details
2 parents 67b7bbd + adc57be commit 72b53ad

File tree

1 file changed

+76
-13
lines changed

1 file changed

+76
-13
lines changed

Diff for: cookbook/session/sessions_directory.rst

+76-13
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,86 @@
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+
<!-- handler_id set to null will use default session handler from php.ini -->
35+
<framework:session handler-id="null" />
36+
</framework:config>
37+
</container>
1238
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``.
39+
.. code-block:: php
40+
41+
// app/config/config.php
42+
$container->loadFromExtension('framework', array(
43+
'session' => array(
44+
// handler_id set to null will use default session handler from php.ini
45+
'handler-id' => null,
46+
),
47+
));
1648
17-
.. note::
49+
With this configuration, changing *where* your session metadata is stored
50+
is entirely up to your ``php.ini`` configuration.
1851

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.
52+
However, if you have the following configuration, Symfony will store the session
53+
data in files in the cache directory ``%kernel.cache_dir%/sessions``. This
54+
means that when you clear the cache, any current sessions will also be deleted:
55+
56+
.. configuration-block::
57+
58+
.. code-block:: yaml
59+
60+
# app/config/config.yml
61+
framework:
62+
session: ~
63+
64+
.. code-block:: xml
65+
66+
<!-- app/config/config.xml -->
67+
<?xml version="1.0" encoding="UTF-8" ?>
68+
<container xmlns="http://symfony.com/schema/dic/services"
69+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
70+
xmlns:framework="http://symfony.com/schema/dic/symfony"
71+
xsi:schemaLocation="http://symfony.com/schema/dic/services
72+
http://symfony.com/schema/dic/services/services-1.0.xsd
73+
http://symfony.com/schema/dic/symfony
74+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
75+
>
76+
<framework:config>
77+
<framework:session />
78+
</framework:config>
79+
</container>
80+
81+
.. code-block:: php
82+
83+
// app/config/config.php
84+
$container->loadFromExtension('framework', array(
85+
'session' => array(),
86+
));
2487
2588
Using a different directory to save session data is one method to ensure
2689
that your current sessions aren't lost when you clear Symfony's cache.

0 commit comments

Comments
 (0)