From bb1817e5156a100fd70ef211ac83e4d962e95ee4 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Thu, 18 Apr 2013 09:30:42 +0100 Subject: [PATCH] Issue #1969846 by rootatwc: Convert session_write_interval() to settings. --- core/includes/session.inc | 4 ++-- .../lib/Drupal/system/Tests/Session/SessionTest.php | 8 +++++++- sites/default/default.settings.php | 8 ++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/core/includes/session.inc b/core/includes/session.inc index a0de5e977a9b..56299151d794 100644 --- a/core/includes/session.inc +++ b/core/includes/session.inc @@ -169,7 +169,7 @@ function _drupal_session_write($sid, $value) { // For performance reasons, do not update the sessions table, unless // $_SESSION has changed or more than 180 has passed since the last update. - if ($is_changed || !isset($user->timestamp) || REQUEST_TIME - $user->timestamp > variable_get('session_write_interval', 180)) { + if ($is_changed || !isset($user->timestamp) || REQUEST_TIME - $user->timestamp > settings()->get('session_write_interval', 180)) { // Either ssid or sid or both will be added from $key below. $fields = array( 'uid' => $user->uid, @@ -206,7 +206,7 @@ function _drupal_session_write($sid, $value) { } // Likewise, do not update access time more than once per 180 seconds. - if ($user->uid && REQUEST_TIME - $user->access > variable_get('session_write_interval', 180)) { + if ($user->uid && REQUEST_TIME - $user->access > settings()->get('session_write_interval', 180)) { db_update('users') ->fields(array( 'access' => REQUEST_TIME diff --git a/core/modules/system/lib/Drupal/system/Tests/Session/SessionTest.php b/core/modules/system/lib/Drupal/system/Tests/Session/SessionTest.php index 53a443e79857..8f5569da9efc 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Session/SessionTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Session/SessionTest.php @@ -228,7 +228,13 @@ function testSessionWrite() { $this->assertEqual($times4->timestamp, $times3->timestamp, 'Sessions table was not updated.'); // Force updating of users and sessions table once per second. - variable_set('session_write_interval', 0); + $this->settingsSet('session_write_interval', 0); + // Write that value also into the test settings.php file. + $settings['settings']['session_write_interval'] = (object) array( + 'value' => 0, + 'required' => TRUE, + ); + $this->writeSettings($settings); $this->drupalGet(''); $times5 = db_query($sql, array(':uid' => $user->uid))->fetchObject(); $this->assertNotEqual($times5->access, $times4->access, 'Users table was updated.'); diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php index a0f1016a9305..ab856464dd40 100644 --- a/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -451,6 +451,14 @@ */ # $settings['mixed_mode_sessions'] = TRUE; +/** + * Session write interval: + * + * Set the minimum interval between each session write to database. + * For performance reasons it defaults to 180. + */ +# $settings['session_write_interval'] = 180; + /** * Base URL (optional). * -- GitLab