From bcf8e93959c993fa8d56311f028621c49a491d16 Mon Sep 17 00:00:00 2001 From: Spine Date: Tue, 7 Oct 2025 07:05:57 +0000 Subject: [PATCH] record mem/cpu stats in every request --- gazelle.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/gazelle.php b/gazelle.php index 64fef3d4d..4e3376e7b 100644 --- a/gazelle.php +++ b/gazelle.php @@ -11,6 +11,21 @@ use Gazelle\Util\Time; require_once __DIR__ . '/lib/bootstrap.php'; global $Cache, $Debug, $Twig; +register_shutdown_function( + function () { + if (preg_match(DEBUG_URI, $_SERVER['REQUEST_URI'])) { + include DEBUG_TRACE; /** @phpstan-ignore-line */ + } + $error = error_get_last(); + global $Debug; + if ($error['type'] == E_ERROR) { + $Debug->saveCase(str_replace(SERVER_ROOT . '/', '', $error['message'])); + } + $Debug->storeMemory(memory_get_usage(true)); + $Debug->storeDuration($Debug->duration() * 1000000); + } +); + // Get the user's actual IP address if they're proxied. if ( !empty($_SERVER['HTTP_X_FORWARDED_FOR']) @@ -135,19 +150,6 @@ $Cache->cache_value('php_' . getmypid(), [ ) ], 600); -register_shutdown_function( - function () { - if (preg_match(DEBUG_URI, $_SERVER['REQUEST_URI'])) { - include DEBUG_TRACE; /** @phpstan-ignore-line */ - } - $error = error_get_last(); - if ($error['type'] == E_ERROR) { - global $Debug; - $Debug->saveCase(str_replace(SERVER_ROOT . '/', '', $error['message'])); - } - } -); - // 4. Display the page header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0'); @@ -176,6 +178,4 @@ try { if (!is_null($Viewer)) { $Debug->profile($Viewer, isset($_REQUEST['profile'])); } - $Debug->storeMemory(memory_get_usage(true)); - $Debug->storeDuration($Debug->duration() * 1000000); }