You are browsing the documentation for Symfony 2.2 which is not maintained anymore.
Consider upgrading your projects to Symfony 5.2.
Configuring the Directory where Sessions Files are Saved
Configuring the Directory where Sessions Files are Saved¶
By default, Symfony stores the session data in the cache directory. This means that when you clear the cache, any current sessions will also be deleted.
Using a different directory to save session data is one method to ensure that your current sessions aren’t lost when you clear Symfony’s cache.
Using a different session save handler is an excellent (yet more complex) method of session management available within Symfony. See Configuring Sessions and Save Handlers for a discussion of session save handlers. There is also an entry in the cookbook about storing sessions in the database.
To change the directory in which Symfony saves session data, you only need
change the framework configuration. In this example, you will change the
session directory to
1 2 3 4
# app/config/config.yml framework: session: save_path: "%kernel.root_dir%/sessions"
1 2 3 4
<!-- app/config/config.xml --> <framework:config> <framework:session save-path="%kernel.root_dir%/sessions" /> </framework:config>
1 2 3 4
// app/config/config.php $container->loadFromExtension('framework', array( 'session' => array('save-path' => "%kernel.root_dir%/sessions"), ));
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.