added functions

main
Anthony 2025-06-17 00:39:43 +08:00
parent 0e8943f762
commit afddd91e27
2 changed files with 37 additions and 9 deletions

View File

@ -444,7 +444,7 @@ actions:
- cmd[cp]: - cmd[cp]:
user: root user: root
commands: commands:
- php /home/litespeed/mbmanager/scripts/check_opcache.php - php /home/litespeed/mbmanager/scripts/check_opcache.php --simple
- return: - return:
type: info type: info
message: "${response.out}" message: "${response.out}"

View File

@ -9,32 +9,60 @@ if (php_sapi_name() !== 'cli') {
exit(1); exit(1);
} }
// Check PHP version and path // 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 Version: " . PHP_VERSION . "\n";
echo "PHP Binary: " . PHP_BINARY . "\n"; echo "PHP Binary: " . PHP_BINARY . "\n";
echo "PHP SAPI: " . php_sapi_name() . "\n"; echo "PHP SAPI: " . php_sapi_name() . "\n";
}
// Check if OPCache is enabled // Check if OPCache is enabled
if (!function_exists('opcache_get_status')) { if (!function_exists('opcache_get_status')) {
if ($simpleStatus) {
echo "OPcache status: Disabled - OPcache is not installed";
} else {
echo json_encode(['status' => 'error', 'message' => 'OPCache is not installed']); echo json_encode(['status' => 'error', 'message' => 'OPCache is not installed']);
}
exit(1); exit(1);
} }
// Get OPCache status // Get OPCache status
$status = opcache_get_status(false); $status = opcache_get_status(false);
if ($status === false) { if ($status === false) {
if ($simpleStatus) {
echo "OPcache status: Error - Failed to get OPcache status";
} else {
echo json_encode(['status' => 'error', 'message' => 'Failed to get OPCache status']); echo json_encode(['status' => 'error', 'message' => 'Failed to get OPCache status']);
}
exit(1); exit(1);
} }
// Get OPCache configuration // Get OPCache configuration
$config = opcache_get_configuration(); $config = opcache_get_configuration();
if ($config === false) { if ($config === false) {
if ($simpleStatus) {
echo "OPcache status: Error - Failed to get OPcache configuration";
} else {
echo json_encode(['status' => 'error', 'message' => 'Failed to get OPCache configuration']); echo json_encode(['status' => 'error', 'message' => 'Failed to get OPCache configuration']);
}
exit(1); 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 = [ $response = [
'status' => 'success', 'status' => 'success',
'data' => [ 'data' => [