3
votes

I use Symfony session to store, and retrieve, the language selected by users on a splash page. If they have no language set they are redirected to the splash directly. This behavior works as expected.

Unfortunately when I clear the cache I got issues with it (I use php app/console cache:clear --env=prod command). Users can access one page then on any click they are redirected to the splash. Afterwards, even if they choose a language they will not be able to go any further than the homepage, any click will redirect again to splash.

If I delete the cache folder manually the error will not occur.

My session related configuration is the following:

framework:
    session:
        handler_id:  ~
        gc_probability: 0

I have no session folder into my cache directory. I can find my session files into my site tmp folder (session id and content match the user session cookie and language choice). They are preserved after cache:clear command but it seems Symfony cannot get values from those files anymore. Also, no new session file is created for those user, and it seems new language choice cannot be written anywhere.

I don't have the error on my local development environment (improved Homestead) but I have it on all my others environments (dev, staging, production)

Using $session->invalidate(); on the splash page will fix the issue. But I would like to understand why it occurs. Any ideas ?

2
Why you set the gc_probability to 0 ? And i suppose you override the session.save_path ? If you have different behavior between environmental checks that the configuration does not changeClément BERTILLON
Honestly no idea regarding gc_probability as I didn't start the project myself. Will remove that settings to use default.Wanjee
session.save_path is overriden neither in Symfony configuration nor in any bundle. This should therefore default to %kernel.cache.dir%/sessions but it is not what occurs, they are stored in the tmp folder. php session.save_path value is set to /srv/www/my_domain/var/tmp and it's the location where session files are written.Wanjee

2 Answers

0
votes

You can change the directory in which Symfony saves session data so when you clear the cache the session is keep alive. You can do this only need change the framework configuration. As example:

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

Further reference in the doc

hope this help

0
votes

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