session gc回收

@param int $lifeTime

@return bool
423497
public function gc($lifeTime = 0)
    {
        if (Config::get('session_user_loc') == 'db') {
            $lifeTime || $lifeTime = $this->lifeTime;
            $this->handler->whereLt('ctime', Cml::$nowTime - $lifeTime)
                ->delete(Config::get('session_user_loc_table'), true, Config::get('session_user_loc_tableprefix'));
        } else {
            //cache 本身会回收
        }
        return true;
    }
583099
public static function gc() {
        global $CFG, $DB;

        // This may take a long time...
        \core_php_time_limit::raise();

        $maxlifetime = $CFG->sessiontimeout;

        try {
            // Kill all sessions of deleted and suspended users without any hesitation.
            $rs = $DB->get_recordset_select('sessions', "userid IN (SELECT id FROM {user} WHERE deleted <> 0 OR suspended <> 0)", array(), 'id DESC', 'id, sid');
            foreach ($rs as $session) {
                self::kill_session($session->sid);
            }
            $rs->close();

            // Kill sessions of users with disabled plugins.
            $auth_sequence = get_enabled_auth_plugins(true);
            $auth_sequence = array_flip($auth_sequence);
            unset($auth_sequence['nologin']); // No login means user cannot login.
            $auth_sequence = array_flip($auth_sequence);

            list($notplugins, $params) = $DB->get_in_or_equal($auth_sequence, SQL_PARAMS_QM, '', false);
            $rs = $DB->get_recordset_select('sessions', "userid IN (SELECT id FROM {user} WHERE auth $notplugins)", $params, 'id DESC', 'id, sid');
            foreach ($rs as $session) {
                self::kill_session($session->sid);
            }
            $rs->close();

            // Now get a list of time-out candidates - real users only.
            $sql = "SELECT u.*, s.sid, s.timecreated AS s_timecreated, s.timemodified AS s_timemodified
                      FROM {user} u
                      JOIN {sessions} s ON s.userid = u.id
                     WHERE s.timemodified < :purgebefore AND u.id <> :guestid";
            $params = array('purgebefore' => (time() - $maxlifetime), 'guestid'=>$CFG->siteguest);

            $authplugins = array();
            foreach ($auth_sequence as $authname) {
                $authplugins[$authname] = get_auth_plugin($authname);
            }
            $rs = $DB->get_recordset_sql($sql, $params);
            foreach ($rs as $user) {
                foreach ($authplugins as $authplugin) {
                    /** @var \auth_plugin_base $authplugin*/
                    if ($authplugin->ignore_timeout_hook($user, $user->sid, $user->s_timecreated, $user->s_timemodified)) {
                        continue 2;
                    }
                }
                self::kill_session($user->sid);
            }
            $rs->close();

            // Delete expired sessions for guest user account, give them larger timeout, there is no security risk here.
            $params = array('purgebefore' => (time() - ($maxlifetime * 5)), 'guestid'=>$CFG->siteguest);
            $rs = $DB->get_recordset_select('sessions', 'userid = :guestid AND timemodified < :purgebefore', $params, 'id DESC', 'id, sid');
            foreach ($rs as $session) {
                self::kill_session($session->sid);
            }
            $rs->close();

            // Delete expired sessions for userid = 0 (not logged in), better kill them asap to release memory.
            $params = array('purgebefore' => (time() - $maxlifetime));
            $rs = $DB->get_recordset_select('sessions', 'userid = 0 AND timemodified < :purgebefore', $params, 'id DESC', 'id, sid');
            foreach ($rs as $session) {
                self::kill_session($session->sid);
            }
            $rs->close();

            // Cleanup letfovers from the first browser access because it may set multiple cookies and then use only one.
            $params = array('purgebefore' => (time() - 60*3));
            $rs = $DB->get_recordset_select('sessions', 'userid = 0 AND timemodified = timecreated AND timemodified < :purgebefore', $params, 'id ASC', 'id, sid');
            foreach ($rs as $session) {
                self::kill_session($session->sid);
            }
            $rs->close();

        } catch (\Exception $ex) {
            debugging('Error gc-ing sessions: '.$ex->getMessage(), DEBUG_NORMAL, $ex->getTrace());
        }
    }
281924
public function gc($maxlifetime)
    {
        $sessions = \Doctrine::getTable($this->_tableName)->findAll();
        foreach ($sessions as $session) {
            if ($this->_getExpirationTime($session) < time()) {
                $session->delete();
            }
        }

        return true;
    }
706354
protected function getExpirationTimestamp($lifetimeInSeconds = false)
    {
        if ($lifetimeInSeconds === false) {
            $lifetimeInSeconds = $this->lifetime;
        }
        if ($lifetimeInSeconds === self::IMMORTAL_LIFETIME) {
            return false;
        } else {
            return date(self::MYSQL_TIMESTAMP, time() + $lifetimeInSeconds);
        }
    }
812786
public function gc(int $maxlifetime) : bool
    {
        static $stmt;
        if (!isset($stmt)) {
            $stmt = $this->pdo->prepare(
                "DELETE FROM cesession_session WHERE dateactive < ?"
            );
        }
        $stmt->execute([date('Y-m-d H:i:s', strtotime("-$maxlifetime second"))]);
        return ($affectedRows = $stmt->rowCount()) && $affectedRows;
    }
84831
public function set_lifetime($lifetime)
    {
        $this->lifetime = max(120, $lifetime);

        // valid time range is now - 1/2 lifetime to now + 1/2 lifetime
        $now = time();
        $this->now = $now - ($now % ($this->lifetime / 2));
    }
1120359
public function gc($lifetime){
        //si la sesión está abierta y tengo lock 
        if($this->opened){
            $fecha= new \DateTime();
            $sql= $this->connection->connection->prepare('DELETE FROM sessions WHERE session_expiration < :fecha');
            $sql->bindValue('fecha', $fecha->format('Y-m-d H:i:s'));
            return $sql->execute() === TRUE;
        }   
        else{
            return FALSE;
        }
    }
1111576
public function setCookie(int $lifetime)
    {
        $cookieDomain = $this->getCookieDomain();
        if ($cookieDomain) {
            \setcookie(self::FE_COOKIE_NAME, 'typo_user_logged_in', $lifetime, '/', $cookieDomain);

            return;
        }
        \setcookie(self::FE_COOKIE_NAME, 'typo_user_logged_in', $lifetime, '/');
    }
1022340
public function regenerate($destroy = false, $lifetime = null)
    {
        if (!$this->isStarted()) {
            return false;
        }
        
        if (null !== $lifetime) {
            ini_set('session.cookie_lifetime', $lifetime);
        }
    
        \Wslim\Ioc::logger('session')->debug(sprintf('[%s]regenerate', static::getId()));
        
        return session_regenerate_id($destroy);
    }
1301307
public function gc($maxlifetime)
    {
        $timestamp = time() - $maxlifetime;

        if ($this->disableLog) {
            Log::temporaryDisable('sql');
        }

        try {
            $this->getAdapter()->delete($this->getTableName())->where('time', '<', $timestamp)->exec();
            return true;

        } catch (DbException $e) {
            Log::emergency($e);
            return false;

        } finally {
            if ($this->disableLog) {
                Log::restoreTemporaryDisablement();
            }
        }
    }
72686
public function remember($lifetime = null)
    {
        $this->shouldCache = true;

        // Make sure something other than the default value (null) is given.
        // Then resolve the DateTime instance from the given value.
        if ($lifetime !== null) {
            $this->cacheLifetime = $this->resolveCacheLifetime($lifetime);
        }

        return $this;
    }
931318
public static function prolong($name, $lifetime)
    {
        $item = static::reach($name);

        if ($item['lifetime'] > 0) {
            $item['lifetime'] += $lifetime;
        } elseif ($item['lifetime'] == 0) {
            $item['lifetime'] = time() + $lifetime;
        }

        static::$register[$name] = $item;

        static::save();

        return true;
    }
759257
public function gc($sessMaxLifeTime) { 
       $hander = 	is_array($this->hander)?$this->hander[0]:$this->hander;
       mysql_query('DELETE FROM '.$this->sessionTable.' WHERE session_expire < '.time(),$hander); 
       return mysql_affected_rows($hander); 
   }
486130
public function _gc($max) {
        $old = time() - $max;
        
        ORM::for_table($this->sessions_table)->raw_execute("DELETE * FROM " . $this->sessions_table . " WHERE access < :old", ['old' => $old]);
    }
428239
public function isExpired($lifetime)
    {
        $interval = $this->createdOn->diff(new \DateTimeImmutable());

        return $interval->s >= (int) $lifetime;
    }
635201
public static function gc()
    {
        if (\version_compare(PHP_VERSION, '7.0.0', '>=')) {
            return \session_gc();
        }
        /*
            Polyfill for PHP < 7
        */
        $initial = array(
            'status' => \session_status(),
            'probability' => \ini_get('session.gc_probability'),
            'divisor' => \ini_get('session.gc_divisor'),
        );
        if ($initial['status'] === PHP_SESSION_DISABLED) {
            return false;
        }
        if ($initial['status'] === PHP_SESSION_ACTIVE) {
            // garbage collection is performed on session_start..
            // close our open session... and restart it
            \session_write_close();
        }
        \ini_set('session.gc_probability', 1);
        \ini_set('session.gc_divisor', 1);
        \session_start();
        \ini_set('session.gc_probability', $initial['probability']);
        \ini_set('session.gc_divisor', $initial['divisor']);
        if ($initial['status'] === PHP_SESSION_NONE) {
            if (self::$status['requestId']) {
                \session_write_close();
            } else {
                \session_destroy();
            }
        }
        return true;
    }
1021834
public function set($key, $value, $lifeTime = 3600)
    {
        if (!$this->isEnabled()) {
            return false;
        }

        return eaccelerator_put($this->prefix() . $key, serialize($value), $lifeTime);
    }