From 426f0b0c3da5ae09aebe48b9e7cc69902ef97e7d Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Sat, 6 Jul 2024 21:01:51 +0300 Subject: [PATCH] Check if opcache is enabled --- src/Inspector/Controller/OpcacheController.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Inspector/Controller/OpcacheController.php b/src/Inspector/Controller/OpcacheController.php index dbfa68a..c2c2732 100644 --- a/src/Inspector/Controller/OpcacheController.php +++ b/src/Inspector/Controller/OpcacheController.php @@ -6,8 +6,7 @@ use Psr\Http\Message\ResponseInterface; use Yiisoft\DataResponse\DataResponseFactoryInterface; - -use function Safe\opcache_get_status; +use Yiisoft\Http\Status; final class OpcacheController { @@ -18,9 +17,15 @@ public function __construct( public function index(): ResponseInterface { + if (!\function_exists('opcache_get_status') || ($status = \opcache_get_status(true)) === false) { + return $this->responseFactory->createResponse([ + 'message' => 'OPcache is not installed or configured', + ], Status::UNPROCESSABLE_ENTITY); + } + return $this->responseFactory->createResponse([ - 'status' => opcache_get_status(true), - 'configuration' => opcache_get_configuration(), + 'status' => $status, + 'configuration' => \opcache_get_configuration(), ]); } }