PHP session times out after only a few minutes

Dave picture Dave · Aug 21, 2015 · Viewed 7.2k times · Source

We have a PHP app (SilverStripe) on a cPanel LAMP shared hosting server. The CMS user is losing their session every couple of minutes. Here are some session settings based on phpinfo() on the hosting platform:

session.gc_maxlifetime = 0
session.gc_divisor = 100
session.gc_probability = 1
session.save_handler = files
session.save_path = /tmp
session.cookie_lifetime = 0

There is no session management in the PHP code. In fact SilverStripe CMS actually pings the server every 5 minutes to keep the session alive but timeouts are happening way before then.

What could cause this?

Answer

Rohan Khude picture Rohan Khude · Aug 21, 2015

Check out php.ini the value set for session.gc_maxlifetime is the ID lifetime in seconds.

I believe the default is 1440 seconds (24 mins)

http://www.php.net/manual/en/session.configuration.php

Edit: As some comments point out, the above is not entirely accurate. A wonderful explanation of why, and how to implement session lifetimes is available here: