note 90351 modified in book.session by danbrown

From: Date: Fri, 17 Apr 2009 14:44:27 +0000
Subject: note 90351 modified in book.session by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153433@lists.php.net to get a copy of this message
There is a nuance we found with session timing out although the user is still active in the session. The problem has to do with never modifying the session variable. The GC will clear the session data files based on their last modification time. Thus if you never modify the session, you simply read from it, then the GC will eventually clean up. To prevent this you need to ensure that your session is modified within the GC delete time. You can accomplish this like below. <?php if( !isset($_SESSION['last_access']) || (time() - $_SESSION['last_access']) > 60 ) $_SESSION['last_access'] = time(); ?> This will update the session every 60s to ensure that the modification date is altered. --was-- There is a nuance we found with session timing out although the user is still active in the session. The problem has to do with never modifying the session variable. The GC will clear the session data files based on their last modification time. Thus if you never modify the session, you simply read from it, then the GC will eventually clean up. To prevent this you need to ensure that your session is modified within the GC delete time. You can accomplish this like below. if( !isset($_SESSION['last_access']) || (time() - $_SESSION['last_access']) > 60 ) $_SESSION['last_access'] = time(); This will update the session every 60s to ensure that the modification date is altered. http://php.net/manual/en/book.session.php

« previous php.notes (#153433) next »