Skip to content

Commit

Permalink
feat: use ini_parse_quantity if available (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinect committed Oct 4, 2023
1 parent f4e45fd commit dcf5fac
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Components/Health/Checker/HealthChecker/PhpChecker.php
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit dcf5fac

Please sign in to comment.