Symfony2 Session and Cache: Cleanup Command

I am using a Symfony session to store and retrieve the language users selected on the splash page. If they don't have a language set, they are redirected directly to the splash. This behavior works as expected.

Unfortunately when I clear the cache I am having problems with it (I am using the command php app/console cache:clear --env=prod

). Users can access one page and then on every click they will be redirected to a splash. After that, even if they choose the language, it will not be able to advance further than the main page, any click will redirect to splash again.

If I delete the cache folder manually, no error occurs.

My session related configuration is as follows:

framework:
    session:
        handler_id:  ~
        gc_probability: 0

      

I don't have a sessions folder in my cache directory. I can find my session files in the tmp folder of my site (session id and content match the user's session cookie and language selection). They persist after the cache: clear command, but it looks like Symfony can no longer get values ​​from these files. Also, no new session file is created for that user, and it seems like a new language cannot be written anywhere.

I have no bug in my local development environment (improved by Homestead), but I have it in all other environments (dev, staging, production)

Using $ session-> invalidate (); the splash page will fix the problem. But I would like to understand why this is happening. Any ideas?

+3


source to share


2 answers


You can change the directory where Symfony stores session data, so when you clear the cache, the session is saved. You can do this, only you need to change the framework configuration. As an example:

#config.yml
framework:
    session:
        save_path: "%kernel.root_dir%/sessions"

      



Further link in doc

hope this help

0


source


Are you working in a multi-server environment? If so, I would recommend storing sessions in the database: http://symfony.com/doc/current/cookbook/configuration/pdo_session_storage.html



0


source







All Articles