Fix session explosion: skip session_start for agent/netscan/ping endpoints

Agent heartbeats (every 10s from 13 agents) were creating empty session files
because session_start() ran unconditionally. Over months this produced millions
of 0-byte files in the session directory, causing PHP session GC to hang and
making all browser API calls intermittently timeout (panels show offline/empty).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-17 13:23:53 +00:00
parent f304ada4d3
commit 025c6d6fec
+7 -1
View File
@@ -8,7 +8,13 @@ require_once __DIR__ . '/../api/config.php';
require_once __DIR__ . '/../api/lib/db.php';
require_once __DIR__ . '/../api/lib/kb_engine.php';
session_start();
// Skip session for agent/netscan/ping — each heartbeat would otherwise create
// an empty session file, producing millions of files that slow session GC for all requests.
$_earlyParts = explode('/', trim(parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH), '/'));
if (($_earlyParts[0] ?? '') === 'api') array_shift($_earlyParts);
if (!in_array($_earlyParts[0] ?? '', ['agent','netscan','ping'], true)) {
session_start();
}
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');