diff --git a/lib/classes/session/manager.php b/lib/classes/session/manager.php index 250399b8e7c..e370597eb69 100644 --- a/lib/classes/session/manager.php +++ b/lib/classes/session/manager.php @@ -689,12 +689,6 @@ class manager { global $PERF, $ME, $CFG; if (self::$sessionactive) { - // If debugging, take a snapshot of session at close and compare on shutdown to detect any accidental mutations. - if (debugging()) { - self::$sessionatclose = (array) $_SESSION['SESSION']; - \core_shutdown_manager::register_function('\core\session\manager::check_mutated_closed_session'); - } - // Grab the time when session lock is released. $PERF->sessionlock['released'] = microtime(true); if (!empty($PERF->sessionlock['gained'])) { @@ -704,6 +698,12 @@ class manager { self::update_recent_session_locks($PERF->sessionlock); self::sessionlock_debugging(); + // If debugging, take a snapshot of session at close and compare on shutdown to detect any accidental mutations. + if (debugging()) { + self::$sessionatclose = (array) $_SESSION['SESSION']; + \core_shutdown_manager::register_function('\core\session\manager::check_mutated_closed_session'); + } + $requireslock = self::$handler->requires_write_lock(); if (!$requireslock || !self::$requireslockdebug) { // Compare the array of the earlier session data with the array now, if