Skip to content

Commit

Permalink
add implementations for checking cli and JIT in OpCacheCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
david-d-h committed Oct 16, 2023
1 parent 431ec02 commit af7f351
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Checks/OpCacheCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,55 @@

class OpCacheCheck extends Check
{
protected bool $checkJit = false;

protected bool $checkCli = false;

public function checkJit(): static
{
$this->checkJit = true;

return $this;
}

public function checkCli(): static
{
$this->checkCli = true;

return $this;
}

public function run(): Result
{
$result = Result::new();

if (! $this->opCacheIsConfigured()) {
return $result->failed('OpCache is not configured to run.');
}

if (! $this->opCacheIsRunning()) {
return $result->failed('OpCache is not running.');
}

if ($this->checkJit && ! $this->isJitEnabled()) {
return $result->failed('OpCache JIT is not running.');
}

return $result->ok('OpCache is running.');
}

protected function opCacheIsConfigured(): bool
{
if (! function_exists('opcache_get_configuration')) {
return false;
}

$configuration = opcache_get_configuration()['directives'];

return $configuration['opcache.enable']
&& $this->checkCli ? $configuration['opcache.enable_cli'] : true;
}

protected function opCacheIsRunning(): bool
{
if (! function_exists('opcache_get_status')) {
Expand All @@ -28,4 +66,16 @@ protected function opCacheIsRunning(): bool

return $configuration['opcache_enabled'] ?? false;
}

protected function isJitEnabled(): bool
{
if (! function_exists('opcache_get_status')) {
return false;
}

$configuration = opcache_get_status()['jit'];

return $configuration['enabled'] && $configuration['on']
?? false;
}
}

0 comments on commit af7f351

Please sign in to comment.