diff --git a/core/includes/session.inc b/core/includes/session.inc index a0de5e977a9b8fcf7c0a2df60ea06c846fd8221c..56299151d794a4c05699d2d6cca98dea69fa6dbc 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 53a443e798578be860d4ebe496b8e125b91b70a3..8f5569da9efcbdb907aae69f82f9fd12f7c69a2e 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 a0f1016a930504103129ebf4e35688703818e563..ab856464dd40f13b7e3cbfff9e543ea25fa871dd 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). *