generated from vormkracht10/laravel-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from vormkracht10/feature/op-cache-check
Feature/op cache check
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace Vormkracht10\LaravelOK\Checks; | ||
|
||
use Vormkracht10\LaravelOK\Checks\Base\Check; | ||
use Vormkracht10\LaravelOK\Checks\Base\Result; | ||
|
||
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')) { | ||
return false; | ||
} | ||
|
||
$configuration = opcache_get_status(); | ||
|
||
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']; | ||
} | ||
} |