note 13368 added to function.session-set-save-handler.php

From: Date: Wed, 13 Jun 2001 16:16:05 +0000
Subject: note 13368 added to function.session-set-save-handler.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-14341@lists.php.net to get a copy of this message
The garbage collection procedure is called when the session is started up with session_start() or implicitly through session_register(). It is not called all the time, but with a probability defined in session.gc_probability in your php.ini. For example, in the example of the previous user, You'd write something like... function gc($maxlifetime) { global $sess_save_path; if (!dir=@opendir($sess_save_path)) { return false; } $return=true; while($file=readdir($dir)) { if (!strstr($file,'sess_')) { continue; } if (strpos($file,'sess_')!=0) { continue; } if (!($atime=@fileatime("$sess_save_path/$file")) { $return=false; continue; } if (time() > $atime + $maxlifetime) { $return = (@unlink("$sess_save_path/$file")) ? $return : false; } } closedir($dir); return $return; } /* I apologize for the bugs, I don't use a file based system. Note that some operating systems are optimized to not record the access time in the file system. If that is the case, modify the code to use touch() and check the modification time. */ -terry http://www.php.net/manual/en/function.session-set-save-handler.php

« previous php.notes (#14341) next »