You are here

private static function CleanerSettingsForm::getSessionSettings in Cleaner 8

Same name and namespace in other branches
  1. 8.2 src/Form/CleanerSettingsForm.php \Drupal\cleaner\Form\CleanerSettingsForm::getSessionSettings()

Gets the session lifetime and expired sessions count.

Return value

array Session lifetime and expired sessions count.

1 call to CleanerSettingsForm::getSessionSettings()
CleanerSettingsForm::buildForm in src/Form/CleanerSettingsForm.php
Form constructor.

File

src/Form/CleanerSettingsForm.php, line 144

Class

CleanerSettingsForm
Class CleanerSettingsForm.

Namespace

Drupal\cleaner\Form

Code

private static function getSessionSettings() {

  // Get cookies params array.
  $lifetime = (int) session_get_cookie_params()['lifetime'];

  // Get current database connection.
  $connection = \Drupal::database();

  // Select old sessions from the sessions db table.
  $count = $connection
    ->select('sessions', 's')
    ->fields('s', [
    'sid',
    'timestamp',
  ])
    ->condition('timestamp', REQUEST_TIME - $lifetime, '<');
  $count = count((array) $count
    ->execute()
    ->fetchCol());
  return [
    'lifetime' => $lifetime,
    'old_sessions' => $count,
  ];
}