Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SessionHandler.php

function 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(int $lifetime) : int|false {
    // 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.
    try {
        return $this->connection
            ->delete('sessions')
            ->condition('timestamp', $this->time
            ->getRequestTime() - $lifetime, '<')
            ->execute();
    } catch (\Exception) {
    }
    return FALSE;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal