Welcome Guest, Not a member yet? Register   Sign In
Session library not garbage collecting
#4

If you are going with a CRON make a CRON script that execute Codeigniter's own gc.

This is a copy of Session_files_driver.php. I think you should execute that one instead.
PHP Code:
    /**
     * Garbage Collector
     *
     * Deletes expired sessions
     *
     * @param    int     $maxlifetime    Maximum lifetime of sessions
     * @return    bool
     */
    
public function gc($maxlifetime)
    {
        if ( ! 
is_dir($this->_config['save_path']) OR ($directory opendir($this->_config['save_path'])) === FALSE)
        {
            
log_message('debug'"Session: Garbage collector couldn't list files under directory '".$this->_config['save_path']."'.");
            return 
$this->_failure;
        }

        
$ts time() - $maxlifetime;

        
$pattern = ($this->_config['match_ip'] === TRUE)
            ? 
'[0-9a-f]{32}'
            
'';

        
$pattern sprintf(
            
'#\A%s'.$pattern.$this->_sid_regexp.'\z#',
            
preg_quote($this->_config['cookie_name'])
        );

        while ((
$file readdir($directory)) !== FALSE)
        {
            
// If the filename doesn't match this pattern, it's either not a session file or is not ours
            
if ( ! preg_match($pattern$file)
                OR ! 
is_file($this->_config['save_path'].DIRECTORY_SEPARATOR.$file)
                OR (
$mtime filemtime($this->_config['save_path'].DIRECTORY_SEPARATOR.$file)) === FALSE
                
OR $mtime $ts)
            {
                continue;
            }

            
unlink($this->_config['save_path'].DIRECTORY_SEPARATOR.$file);
        }

        
closedir($directory);

        return 
$this->_success;
    } 
Reply


Messages In This Thread
Session library not garbage collecting - by jhob - 01-26-2020, 04:48 AM
RE: Session library not garbage collecting - by jreklund - 01-27-2020, 11:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB