Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ parameters:
paths:
- src
reportUnmatchedIgnoredErrors: false
ignoreErrors:
-
message: "#no value type specified in iterable type array#"
17 changes: 5 additions & 12 deletions src/Components/Health/Checker/HealthChecker/PhpChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Frosh\Tools\Components\Health\Checker\CheckerInterface;
use Frosh\Tools\Components\Health\HealthCollection;
use Frosh\Tools\Components\Health\SettingsResult;
use Frosh\Tools\FroshTools;

class PhpChecker implements HealthCheckerInterface, CheckerInterface
{
Expand All @@ -19,14 +20,6 @@ public function collect(HealthCollection $collection): void
$this->checkPcreJitActive($collection);
}

private function formatSize(float $size): string
{
$base = log($size) / log(1024);
$suffix = ['', 'k', 'M', 'G', 'T'][floor($base)];

return (1024 ** ($base - floor($base))) . $suffix;
}

private function checkPhp(HealthCollection $collection): void
{
$minPhpVersion = '8.2.0';
Expand Down Expand Up @@ -90,8 +83,8 @@ private function checkMemoryLimit(HealthCollection $collection): void
SettingsResult::error(
'php-memory-limit',
'Memory-Limit',
$this->formatSize($currentMemoryLimit),
'min ' . $this->formatSize($minMemoryLimit),
FroshTools::formatSize($currentMemoryLimit),
'min ' . FroshTools::formatSize($minMemoryLimit),
),
);

Expand All @@ -101,8 +94,8 @@ private function checkMemoryLimit(HealthCollection $collection): void
$collection->add(SettingsResult::ok(
'php-memory-limit',
'Memory-Limit',
$this->formatSize($currentMemoryLimit),
'min ' . $this->formatSize($minMemoryLimit),
FroshTools::formatSize($currentMemoryLimit),
'min ' . FroshTools::formatSize($minMemoryLimit),
));
}

Expand Down
96 changes: 96 additions & 0 deletions src/Components/Health/Checker/HealthChecker/PhpFpmChecker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Health\Checker\HealthChecker;

use Frosh\Tools\Components\Health\Checker\CheckerInterface;
use Frosh\Tools\Components\Health\HealthCollection;
use Frosh\Tools\Components\Health\SettingsResult;
use Frosh\Tools\FroshTools;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

class PhpFpmChecker implements HealthCheckerInterface, CheckerInterface
{
public function __construct(
#[Autowire(param: 'shopware.deployment.cluster_setup')]
private readonly bool $clusterSetup,
) {
}

public function collect(HealthCollection $collection): void
{
if ($this->clusterSetup) {
return;
}

if (\function_exists('fpm_get_status') === false) {
return;
}

$fpmStatus = \fpm_get_status();

if ($fpmStatus === false) {
return;
}

$this->checkListenQueue($fpmStatus, $collection);
$this->checkMaxChildren($fpmStatus, $collection);
$this->checkMemoryPeak($fpmStatus, $collection);
}

private function checkListenQueue(array $fpmStatus, HealthCollection $collection): void
{
$listenQueue = $fpmStatus['max-listen-queue'] ?? 0;

$status = SettingsResult::ok(
'php-fpm-max-listen-queue',
'PHP FPM max listen queue',
(string) $listenQueue,
'0',
'https://www.php.net/manual/en/fpm.status.php#:~:text=a%20free%20process.-,max%20listen%20queue,-The%20maximum%20number'
);

if ($listenQueue > 0) {
$status->state = SettingsResult::WARNING;
}

$collection->add($status);
}

private function checkMaxChildren(array $fpmStatus, HealthCollection $collection): void
{
$maxChildrenReached = (bool) ($fpmStatus['max-children-reached'] ?? false);

$status = SettingsResult::ok(
'php-fpm-max-children-reached',
'PHP FPM max children reached',
$maxChildrenReached ? 'yes' : 'no',
'no',
'https://www.php.net/manual/en/fpm.status.php#:~:text=max%20children%20reached'
);

if ($maxChildrenReached) {
$status->state = SettingsResult::WARNING;
}

$collection->add($status);
}

private function checkMemoryPeak(array $fpmStatus, HealthCollection $collection): void
{
$memoryPeak = $fpmStatus['memory-peak'] ?? 0;

$memoryPeak = FroshTools::formatSize($memoryPeak);

$collection->add(
SettingsResult::ok(
'php-fpm-memory-peak',
'PHP FPM memory peak',
$memoryPeak,
'',
'https://www.php.net/manual/en/fpm.status.php#:~:text=memory%20peak'
)
);
}
}
8 changes: 8 additions & 0 deletions src/FroshTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public function build(ContainerBuilder $container): void
$container->addCompilerPass(new DisableElasticsearchCompilerPass());
}

public static function formatSize(float $size): string
{
$base = log($size) / log(1024);
$suffix = ['', 'k', 'M', 'G', 'T'][floor($base)];

return round(1024 ** ($base - floor($base)), 2) . $suffix;
}

protected function createContainerExtension(): FroshToolsExtension
{
return new FroshToolsExtension();
Expand Down