diff --git a/Stopwatch/Stopwatch.php b/Stopwatch/Stopwatch.php index 4f1d84b..b0b48c8 100644 --- a/Stopwatch/Stopwatch.php +++ b/Stopwatch/Stopwatch.php @@ -4,7 +4,8 @@ class Stopwatch { - private const FLUSH_TIMERS_LIMIT = 1000; + private const FLUSH_TIMERS_LIMIT = 10000; + 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); } }