From aa6dfa841c8a1595fbeabf74844239eaa62ca5c4 Mon Sep 17 00:00:00 2001 From: Rashit Nadrshin Date: Tue, 13 May 2025 15:23:22 +0500 Subject: [PATCH 1/2] fix replace http response code on pinba_flush() call --- Stopwatch/Stopwatch.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Stopwatch/Stopwatch.php b/Stopwatch/Stopwatch.php index 4f1d84b..c29c0cf 100644 --- a/Stopwatch/Stopwatch.php +++ b/Stopwatch/Stopwatch.php @@ -5,6 +5,7 @@ class Stopwatch { private const FLUSH_TIMERS_LIMIT = 1000; + private const RESPONSE_OK_CODE = 200; protected $enabled = false; protected $initTags = []; @@ -73,8 +74,19 @@ public function add(array $tags, $time): void private function flushIfTimersLimitReached(): void { $timersCount = count(pinba_timers_get(PINBA_ONLY_STOPPED_TIMERS)); - if ($timersCount >= self::FLUSH_TIMERS_LIMIT) { - pinba_flush($this->getScriptName(), PINBA_FLUSH_ONLY_STOPPED_TIMERS); + if ($timersCount < self::FLUSH_TIMERS_LIMIT) { + return; + } + + $originalCode = http_response_code(); + $needReplaceCode = is_int($originalCode) && self::RESPONSE_OK_CODE !== $originalCode; + + if ($needReplaceCode) { + http_response_code(self::RESPONSE_OK_CODE); + } + pinba_flush($this->getScriptName(), PINBA_FLUSH_ONLY_STOPPED_TIMERS); + if ($needReplaceCode) { + http_response_code($originalCode); } } From ae58659d04554bc53ffa27374a68abefa078b3cf Mon Sep 17 00:00:00 2001 From: Rashit Nadrshin Date: Tue, 13 May 2025 16:37:36 +0500 Subject: [PATCH 2/2] Increased FLUSH_TIMERS_LIMIT from 1000 to 10000 --- Stopwatch/Stopwatch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stopwatch/Stopwatch.php b/Stopwatch/Stopwatch.php index c29c0cf..b0b48c8 100644 --- a/Stopwatch/Stopwatch.php +++ b/Stopwatch/Stopwatch.php @@ -4,7 +4,7 @@ class Stopwatch { - private const FLUSH_TIMERS_LIMIT = 1000; + private const FLUSH_TIMERS_LIMIT = 10000; private const RESPONSE_OK_CODE = 200; protected $enabled = false;