11..index ::
22 single: Sessions, sessions directory
33
4- Configuring the Directorywhere Sessions Files are Saved
4+ Configuring the DirectoryWhere Sessions Files are Saved
55========================================================
66
7- By default, Symfony stores the session data in the cache directory. This
8- means that when you clear the cache, any current sessions will also be
9- deleted.
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.
10+
11+ ..note ::
12+
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 ``.
16+
17+ ..note ::
18+
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.
1024
1125Using a different directory to save session data is one method to ensure
1226that your current sessions aren't lost when you clear Symfony's cache.
@@ -30,18 +44,34 @@ session directory to ``app/sessions``:
3044# app/config/config.yml
3145framework :
3246session :
47+ handler_id :session.handler.native_file
3348save_path :" %kernel.root_dir%/sessions"
3449
3550 ..code-block ::xml
3651
3752<!-- app/config/config.xml-->
38- <framework : config >
39- <framework : session save-path =" %kernel.root_dir%/sessions" />
40- </framework : config >
53+ <?xml version =" 1.0" encoding =" UTF-8" ?>
54+ <container xmlns =" http://symfony.com/schema/dic/services"
55+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
56+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
57+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
58+ http://symfony.com/schema/dic/services/services-1.0.xsd
59+ http://symfony.com/schema/dic/symfony
60+ http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
61+ >
62+ <framework : config >
63+ <framework : session handler-id =" session.handler.native_file" />
64+ <framework : session save-path =" %kernel.root_dir%/sessions" />
65+ </framework : config >
66+ </container >
4167
4268 ..code-block ::php
4369
4470 // app/config/config.php
4571 $container->loadFromExtension('framework', array(
46- 'session' => array('save-path' => "%kernel.root_dir%/sessions"),
72+ 'session' => array(
73+ 'handler-id' => 'session.handler.native_file',
74+ 'save-path' => '%kernel.root_dir%/sessions',
75+ ),
4776 ));
77+