From dcf5fac059ab65eecafab8e6a4a4a2596ff0b3af Mon Sep 17 00:00:00 2001 From: tinect Date: Wed, 4 Oct 2023 10:53:08 +0200 Subject: [PATCH] feat: use ini_parse_quantity if available (#222) --- .../Health/Checker/HealthChecker/PhpChecker.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Components/Health/Checker/HealthChecker/PhpChecker.php b/src/Components/Health/Checker/HealthChecker/PhpChecker.php index b43b961..ef2dc5d 100644 --- a/src/Components/Health/Checker/HealthChecker/PhpChecker.php +++ b/src/Components/Health/Checker/HealthChecker/PhpChecker.php @@ -80,7 +80,7 @@ private function checkMaxExecutionTime(HealthCollection $collection): void private function checkMemoryLimit(HealthCollection $collection): void { - $minMemoryLimit = $this->decodePhpSize('512m'); + $minMemoryLimit = $this->parseQuantity('512m'); $currentMemoryLimit = \ini_get('memory_limit'); if ($currentMemoryLimit === false) { $collection->add( @@ -95,7 +95,7 @@ private function checkMemoryLimit(HealthCollection $collection): void return; } - $currentMemoryLimit = $this->decodePhpSize($currentMemoryLimit); + $currentMemoryLimit = $this->parseQuantity($currentMemoryLimit); if ($currentMemoryLimit < $minMemoryLimit) { $collection->add( SettingsResult::error( @@ -143,8 +143,13 @@ private function checkPcreJitActive(HealthCollection $collection): void $collection->add(SettingsResult::warning('pcre-jit', $snippet, 'not active', 'active')); } - private function decodePhpSize(string $val): float + private function parseQuantity(string $val): float { + //TODO: remove condition and own calculation when min php version is 8.2 + if (\function_exists('ini_parse_quantity')) { + return (float) \ini_parse_quantity($val); + } + $val = mb_strtolower(trim($val)); $last = mb_substr($val, -1);