|
4 | 4 | Configuring the Directory Where Sessions Files are Saved
|
5 | 5 | ========================================================
|
6 | 6 |
|
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: |
10 | 10 |
|
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> |
12 | 38 |
|
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 | + )); |
16 | 48 |
|
17 |
| -.. note:: |
| 49 | +With this configuration, changing *where* your session metadata is stored |
| 50 | +is entirely up to your ``php.ini`` configuration. |
18 | 51 |
|
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 | + )); |
24 | 87 |
|
25 | 88 | Using a different directory to save session data is one method to ensure
|
26 | 89 | that your current sessions aren't lost when you clear Symfony's cache.
|
|
0 commit comments