diff --git a/mbadmin.jps b/mbadmin.jps index 789df9b..9c4ed58 100644 --- a/mbadmin.jps +++ b/mbadmin.jps @@ -444,7 +444,7 @@ actions: - cmd[cp]: user: root commands: - - php /home/litespeed/mbmanager/scripts/check_opcache.php + - php /home/litespeed/mbmanager/scripts/check_opcache.php --simple - return: type: info message: "${response.out}" diff --git a/scripts/check_opcache.php b/scripts/check_opcache.php index 6834205..61f07ac 100644 --- a/scripts/check_opcache.php +++ b/scripts/check_opcache.php @@ -9,32 +9,60 @@ if (php_sapi_name() !== 'cli') { exit(1); } -// Check PHP version and path -echo "PHP Version: " . PHP_VERSION . "\n"; -echo "PHP Binary: " . PHP_BINARY . "\n"; -echo "PHP SAPI: " . php_sapi_name() . "\n"; +// Check for simple status flag +$simpleStatus = isset($argv[1]) && $argv[1] === '--simple'; + +// Check PHP version and path (only if not simple mode) +if (!$simpleStatus) { + echo "PHP Version: " . PHP_VERSION . "\n"; + echo "PHP Binary: " . PHP_BINARY . "\n"; + echo "PHP SAPI: " . php_sapi_name() . "\n"; +} // Check if OPCache is enabled if (!function_exists('opcache_get_status')) { - echo json_encode(['status' => 'error', 'message' => 'OPCache is not installed']); + if ($simpleStatus) { + echo "OPcache status: Disabled - OPcache is not installed"; + } else { + echo json_encode(['status' => 'error', 'message' => 'OPCache is not installed']); + } exit(1); } // Get OPCache status $status = opcache_get_status(false); if ($status === false) { - echo json_encode(['status' => 'error', 'message' => 'Failed to get OPCache status']); + if ($simpleStatus) { + echo "OPcache status: Error - Failed to get OPcache status"; + } else { + echo json_encode(['status' => 'error', 'message' => 'Failed to get OPCache status']); + } exit(1); } // Get OPCache configuration $config = opcache_get_configuration(); if ($config === false) { - echo json_encode(['status' => 'error', 'message' => 'Failed to get OPCache configuration']); + if ($simpleStatus) { + echo "OPcache status: Error - Failed to get OPcache configuration"; + } else { + echo json_encode(['status' => 'error', 'message' => 'Failed to get OPCache configuration']); + } exit(1); } -// Format the response +// If simple status requested, just return enabled/disabled +if ($simpleStatus) { + $enabled = $config['directives']['opcache.enable']; + if ($enabled) { + echo "OPcache status: Enabled"; + } else { + echo "OPcache status: Disabled"; + } + exit(0); +} + +// Format the full response (original functionality) $response = [ 'status' => 'success', 'data' => [