Symfony2 sessions not working as expected / session keeps timing out

前端 未结 5 1893
后悔当初
后悔当初 2021-01-03 00:31

My Symfony2 application displays a main page, and from there on it primarily uses AJAX requests to display content to the user via modals.

I\'ve noticed that after t

5条回答
  •  一向
    一向 (楼主)
    2021-01-03 01:04

    The problem:

    It turns out that on Debian / Ubuntu systems, there is a system cronjob which runs every 30 minutes, cleaning out all "old" sessions. Herein lies the problem.

    The cronjob doesn't actually know what constitutes "old". The cronjob simply calls a PHP-CLI script located at /usr/lib/php5/maxlifetime which then removes all session files that exceed a certain age. Since the script is involved by PHP-CLI, and independently of Symfony2, it has no idea what values you specified for gc_maxlifetime and cookie_lifetime in your Symfony2 config file. Instead, if just defaults to using the session.cookie_lifetime and session.gc_maxlifetime values from the /etc/php5/cli/php.ini config file, which by default, is 24 minutes. So no matter what you specify in your Symfony2 config file, if you are idle for too long, your session will be removed.


    The solution:

    • Either delete the cronjob file at /etc/cron.d/php5 or,
    • Store your sessions in a database where they can't be touched by the cronjob

提交回复
热议问题