summaryrefslogtreecommitdiff
path: root/includes/objectcache/ObjectCacheSessionHandler.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/objectcache/ObjectCacheSessionHandler.php')
-rw-r--r--includes/objectcache/ObjectCacheSessionHandler.php45
1 files changed, 43 insertions, 2 deletions
diff --git a/includes/objectcache/ObjectCacheSessionHandler.php b/includes/objectcache/ObjectCacheSessionHandler.php
index 789f1e3b..2a5d6955 100644
--- a/includes/objectcache/ObjectCacheSessionHandler.php
+++ b/includes/objectcache/ObjectCacheSessionHandler.php
@@ -21,6 +21,8 @@
* @ingroup Cache
*/
+use MediaWiki\Logger\LoggerFactory;
+
/**
* Session storage in object cache.
* Used if $wgSessionsInObjectCache is true.
@@ -106,7 +108,11 @@ class ObjectCacheSessionHandler {
* @return mixed Session data
*/
static function read( $id ) {
+ $stime = microtime( true );
$data = self::getCache()->get( self::getKey( $id ) );
+ $real = microtime( true ) - $stime;
+
+ RequestContext::getMain()->getStats()->timing( "session.read", 1000 * $real );
self::$hashCache = array( $id => self::getHash( $data ) );
@@ -127,7 +133,11 @@ class ObjectCacheSessionHandler {
if ( !isset( self::$hashCache[$id] )
|| self::getHash( $data ) !== self::$hashCache[$id]
) {
+ $stime = microtime( true );
self::getCache()->set( self::getKey( $id ), $data, $wgObjectCacheSessionExpiry );
+ $real = microtime( true ) - $stime;
+
+ RequestContext::getMain()->getStats()->timing( "session.write", 1000 * $real );
}
return true;
@@ -140,7 +150,11 @@ class ObjectCacheSessionHandler {
* @return bool Success
*/
static function destroy( $id ) {
+ $stime = microtime( true );
self::getCache()->delete( self::getKey( $id ) );
+ $real = microtime( true ) - $stime;
+
+ RequestContext::getMain()->getStats()->timing( "session.destroy", 1000 * $real );
return true;
}
@@ -157,10 +171,37 @@ class ObjectCacheSessionHandler {
}
/**
- * Shutdown function. See the comment inside ObjectCacheSessionHandler::install
- * for rationale.
+ * Shutdown function.
+ * See the comment inside ObjectCacheSessionHandler::install for rationale.
*/
static function handleShutdown() {
session_write_close();
}
+
+ /**
+ * Pre-emptive session renewal function
+ */
+ static function renewCurrentSession() {
+ global $wgObjectCacheSessionExpiry;
+
+ // Once a session is at half TTL, renew it
+ $window = $wgObjectCacheSessionExpiry / 2;
+ $logger = LoggerFactory::getInstance( 'SessionHandler' );
+
+ $now = microtime( true );
+ // Session are only written in object stores when $_SESSION changes,
+ // which also renews the TTL ($wgObjectCacheSessionExpiry). If a user
+ // is active but not causing session data changes, it may suddenly
+ // expire as they view a form, blocking the first submission.
+ // Make a dummy change every so often to avoid this.
+ if ( !isset( $_SESSION['wsExpiresUnix'] ) ) {
+ $_SESSION['wsExpiresUnix'] = $now + $wgObjectCacheSessionExpiry;
+
+ $logger->info( "Set expiry for session " . session_id(), array() );
+ } elseif ( ( $now + $window ) > $_SESSION['wsExpiresUnix'] ) {
+ $_SESSION['wsExpiresUnix'] = $now + $wgObjectCacheSessionExpiry;
+
+ $logger->info( "Renewed session " . session_id(), array() );
+ }
+ }
}