2

Possible Duplicate:
PHP sessions timing out to quickly

In my .htaccess file I have set

php_value session.gc_maxlifetime 14400 

i.e. for 4 hours

if I verify using echo ini_get('session.gc_maxlifetime'); I get 14400. But still my session expires in, say, less than 2 hours.

What do you think is going wrong here? any help appreciated. Thanks

Community
  • 1
  • 1
ChaCha
  • 23
  • 3

2 Answers2

6
  • Some distributions (Debian, at least) have a cronjob that removes old sessions a regular interval. This cronjob gets the session.gc_maxlifetime setting from the system's php.ini and thus ignore your vhost config.

    Solutions:

    • Set session.gc_maxlifetime in the system's php.int (e.g. /etc/php5/apache2/php.ini)
    • Move the sessions for this vhost to a separate directory (set session.save_path)                     
  • An other probable cause is that the session cookie expire before session itself. Make sure that the session.cookie_lifetime variable is at least equal to session.gc_maxlifetime (or 0).
Arnaud Le Blanc
  • 98,321
  • 23
  • 206
  • 194
  • If I set separate directory using sesssion.save_path would the old/expired session files be cleaned as usual by the system? Or I need to tell it somehow? Thanks – ChaCha Sep 15 '11 at 10:10
  • Yes, they will be cleaned by PHP at a regular interval (defined by the other session.gc_ settings) – Arnaud Le Blanc Sep 15 '11 at 10:11
  • I've just checked session.cookie_lifetime value and it is 0 (zero) Do you think it could be causing it? Its great that files be cleaned auto. Thanks. – ChaCha Sep 15 '11 at 10:14
  • `0` means that the cookie won't expire until you close the browser – Arnaud Le Blanc Sep 15 '11 at 10:17
0

If you're on a Debian machine, you might have an automatically installed cronjob, that deletes sessions. Look at this SO question and specifically Paul Dixon's answer.

Community
  • 1
  • 1
Boldewyn
  • 81,211
  • 44
  • 156
  • 212