1
1
.. index ::
2
2
single: Sessions, sessions directory
3
3
4
- Configuring the Directory where Sessions Files are Saved
4
+ Configuring the Directory Where Sessions Files are Saved
5
5
========================================================
6
6
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.
10
24
11
25
Using a different directory to save session data is one method to ensure
12
26
that your current sessions aren't lost when you clear Symfony's cache.
@@ -30,18 +44,34 @@ session directory to ``app/sessions``:
30
44
# app/config/config.yml
31
45
framework :
32
46
session :
47
+ handler_id : session.handler.native_file
33
48
save_path : " %kernel.root_dir%/sessions"
34
49
35
50
.. code-block :: xml
36
51
37
52
<!-- 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 >
41
67
42
68
.. code-block :: php
43
69
44
70
// app/config/config.php
45
71
$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
+ ),
47
76
));
77
+
0 commit comments