PHP session expiring too early

元气小坏坏 提交于 2020-01-15 11:33:33

问题


I have an issue, my apps sessions are expiring unexpectedly after about 15 minutes. I need them to expire after 4 hours.

The server is Centos 5.5, PHP is 5.3.2.

Below is my code (included in an global header).

<?php
session_name('MobileSuiteHQ');
if(!session_id()) {
    session_start();
}
ini_set('memory_limit', '512M');
ini_set('session.gc_maxlifetime', 14400000);
ini_set('session.cookie_lifetime', 14400000);
ini_set('session.gc_divisor', 1000);
ini_set('session.use_cookies', 0);
ini_set('max_execution_time', 300);
ini_set('session.name','MobileSuiteHQ');
?>

My .htaccess file contains:

php_value session.gc_maxlifetime 14400000
php_value session.cookie_lifetime 14400000
php_value session.use_cookies 0
php_value session.gc_divisor 1000

Any help or insight would be greatful.

EDIT: I was unable to login when i updated my .htaccess file, the session wasn't starting. So I have now removed:

php_value session.use_cookies 0

which now allows me to login.


回答1:


On initial examination, I'd lower your gc_maxlifetime and cookie_lifetime settings. I suspect that 14400000 is a little high for PHP to cope with (in theory, a 32-bit OS should be able to go up to 2147483647, but this could still be a factor).

If you only need 4 hours of lifetime, then 14400 would be a perfect setting, and may resolve your problem for the reason mentioned above.




回答2:


I dont know about CentOS, but on Ubuntu the php5 package installs a /etc/cron.d/php5 file that'll remove 'untouched for 24min' session files on the :9 and :39 of every hour. So you have a minimum of 24min and max of 54min sessions.



来源:https://stackoverflow.com/questions/4936207/php-session-expiring-too-early

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!