function SessionHandler::gc

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Session/SessionHandler.php \Drupal\Core\Session\SessionHandler::gc()
  2. 10 core/lib/Drupal/Core/Session/SessionHandler.php \Drupal\Core\Session\SessionHandler::gc()
  3. 11.x core/lib/Drupal/Core/Session/SessionHandler.php \Drupal\Core\Session\SessionHandler::gc()

File

core/lib/Drupal/Core/Session/SessionHandler.php, line 126

Class

SessionHandler
Default session handler.

Namespace

Drupal\Core\Session

Code

public function gc($lifetime) {
    // Be sure to adjust 'php_value session.gc_maxlifetime' to a large enough
    // value. For example, if you want user sessions to stay in your database
    // for three weeks before deleting them, you need to set gc_maxlifetime
    // to '1814400'. At that value, only after a user doesn't log in after
    // three weeks (1814400 seconds) will their session be removed.
    $this->connection
        ->delete('sessions')
        ->condition('timestamp', REQUEST_TIME - $lifetime, '<')
        ->execute();
    return TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.