Better session control

This commit is contained in:
Eric Espie
2026-02-05 09:26:50 +01:00
parent f9272ac2ed
commit 863dd67302
2 changed files with 21 additions and 10 deletions

View File

@@ -1367,6 +1367,12 @@ try {
DisplayWelcomePopup($oP);
$oKPI->ComputeAndReport('Compute page');
$oP->output();
if (Session::$fLastStartTime !== 0.0) {
IssueLog::Warning('Session left open for: '.(microtime(true) - Session::$fLastStartTime));
}
if (\PHP_SESSION_NONE !== session_status()) {
IssueLog::Warning('Session left open by a lib');
}
} catch (Exception $e) {
$oErrorPage = new ErrorPage(Dict::S('UI:PageTitle:FatalError'));
if ($e instanceof SecurityException) {

View File

@@ -8,6 +8,7 @@
namespace Combodo\iTop\Application\Helper;
use Combodo\iTop\SessionTracker\SessionHandler;
use IssueLog;
use utils;
/**
@@ -24,29 +25,31 @@ class Session
/** @var bool */
protected static $bIsInitialized = false;
/** @var bool */
protected static $bSessionStarted = false;
/** @var bool */
public static $bAllowCLI = false;
public static float $fLastStartTime;
public static function Start()
{
if (self::IsModeCLI()) {
return;
}
static::$fLastStartTime = microtime(true);
if (!self::$bIsInitialized) {
SessionHandler::session_set_save_handler();
session_name('itop-'.md5(APPROOT));
}
self::$bIsInitialized = true;
if (!self::$bSessionStarted) {
if (\PHP_SESSION_NONE === session_status()) {
if (!is_null(self::$iSessionId)) {
if (session_id(self::$iSessionId) === false) {
session_regenerate_id(true);
}
}
self::$bSessionStarted = session_start();
session_start();
self::$iSessionId = session_id();
}
}
@@ -58,10 +61,10 @@ class Session
}
session_regenerate_id($bDeleteOldSession);
if (self::$bSessionStarted) {
if (\PHP_SESSION_NONE !== session_status()) {
self::WriteClose();
}
self::$bSessionStarted = session_start();
session_start();
self::$iSessionId = session_id();
}
@@ -71,10 +74,12 @@ class Session
return;
}
if (self::$bSessionStarted) {
if (\PHP_SESSION_NONE !== session_status()) {
session_write_close();
self::$bSessionStarted = false;
}
IssueLog::Trace('Session close elapsed: '.(microtime(true) - static::$fLastStartTime), 'Session');
static::$fLastStartTime = 0;
}
/**
@@ -96,7 +101,7 @@ class Session
$sSessionVar = &$sSessionVar[$key];
}
$sSessionVar = $value;
if (!self::$bSessionStarted) {
if (\PHP_SESSION_NONE === session_status()) {
self::Start();
$_SESSION = $aSession;
self::WriteClose();
@@ -124,7 +129,7 @@ class Session
$sPrevKey = $sKey;
}
}
if (!self::$bSessionStarted) {
if (\PHP_SESSION_NONE === session_status()) {
self::Start();
unset($sSessionVar[$sKey]);
$_SESSION = $aSession;