I have this in my code but it does not seem to have any affect on the server. I set session gc_maxlifetime
time 4 hours but it does not work. Every 15 minutes it redirects to the login page.
What can I change to avoid unexpected session expiration? In Local it works fine but on the server it create problem.
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 100);
ini_set('session.cookie_secure', FALSE);
ini_set('session.use_only_cookies', TRUE);
ini_set('session.gc_maxlifetime',14400); //4 hour
setcookie("_lid", $lid, time() + 14400);
//set cokkies expiretime
$sessionCookieExpireTime=8*60*60;
session_set_cookie_params($sessionCookieExpireTime);
The problem is that the session garbage collection is done via a cronjob under /etc/cron.d/php
or /etc/crontab
.
This is set to every 30 minutes afaik.
Change it to 0 */4 * * *
to let it do its job every 4 hours.
The cronjob looks like:
09,39 * * * * root [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -delete
To advertise my personal opinion, I'd install memcached
server and use it as your session handler. It's faster and better to control without a cronjob deleting your files.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.