Added more detailed functions
parent
05fb58d7d2
commit
a2021a3e35
|
@ -479,7 +479,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 --summary
|
||||||
- return:
|
- return:
|
||||||
type: info
|
type: info
|
||||||
message: "${response.out}"
|
message: "${response.out}"
|
||||||
|
@ -488,7 +488,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 --statistics
|
||||||
- return:
|
- return:
|
||||||
type: info
|
type: info
|
||||||
message: "${response.out}"
|
message: "${response.out}"
|
||||||
|
@ -497,7 +497,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 --settings
|
||||||
- return:
|
- return:
|
||||||
type: info
|
type: info
|
||||||
message: "${response.out}"
|
message: "${response.out}"
|
||||||
|
|
|
@ -9,11 +9,11 @@ if (php_sapi_name() !== 'cli') {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for simple status flag
|
// Check for different output modes
|
||||||
$simpleStatus = isset($argv[1]) && $argv[1] === '--simple';
|
$mode = isset($argv[1]) ? $argv[1] : 'full';
|
||||||
|
|
||||||
// Check PHP version and path (only if not simple mode)
|
// Check PHP version and path (only if not simple mode)
|
||||||
if (!$simpleStatus) {
|
if ($mode !== '--simple') {
|
||||||
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";
|
||||||
|
@ -21,7 +21,7 @@ if (!$simpleStatus) {
|
||||||
|
|
||||||
// Check if OPCache is enabled
|
// Check if OPCache is enabled
|
||||||
if (!function_exists('opcache_get_status')) {
|
if (!function_exists('opcache_get_status')) {
|
||||||
if ($simpleStatus) {
|
if ($mode === '--simple') {
|
||||||
echo "OPcache status: Disabled - OPcache is not installed";
|
echo "OPcache status: Disabled - OPcache is not installed";
|
||||||
} else {
|
} else {
|
||||||
echo json_encode(['status' => 'error', 'message' => 'OPCache is not installed']);
|
echo json_encode(['status' => 'error', 'message' => 'OPCache is not installed']);
|
||||||
|
@ -32,7 +32,7 @@ if (!function_exists('opcache_get_status')) {
|
||||||
// Get OPCache status
|
// Get OPCache status
|
||||||
$status = opcache_get_status(false);
|
$status = opcache_get_status(false);
|
||||||
if ($status === false) {
|
if ($status === false) {
|
||||||
if ($simpleStatus) {
|
if ($mode === '--simple') {
|
||||||
echo "OPcache status: Error - Failed to get OPcache status";
|
echo "OPcache status: Error - Failed to get OPcache status";
|
||||||
} else {
|
} else {
|
||||||
echo json_encode(['status' => 'error', 'message' => 'Failed to get OPCache status']);
|
echo json_encode(['status' => 'error', 'message' => 'Failed to get OPCache status']);
|
||||||
|
@ -43,7 +43,7 @@ if ($status === false) {
|
||||||
// Get OPCache configuration
|
// Get OPCache configuration
|
||||||
$config = opcache_get_configuration();
|
$config = opcache_get_configuration();
|
||||||
if ($config === false) {
|
if ($config === false) {
|
||||||
if ($simpleStatus) {
|
if ($mode === '--simple') {
|
||||||
echo "OPcache status: Error - Failed to get OPcache configuration";
|
echo "OPcache status: Error - Failed to get OPcache configuration";
|
||||||
} else {
|
} else {
|
||||||
echo json_encode(['status' => 'error', 'message' => 'Failed to get OPCache configuration']);
|
echo json_encode(['status' => 'error', 'message' => 'Failed to get OPCache configuration']);
|
||||||
|
@ -51,48 +51,143 @@ if ($config === false) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If simple status requested, just return enabled/disabled
|
// Handle different output modes
|
||||||
if ($simpleStatus) {
|
switch ($mode) {
|
||||||
$enabled = $config['directives']['opcache.enable'];
|
case '--simple':
|
||||||
if ($enabled) {
|
$enabled = $config['directives']['opcache.enable'];
|
||||||
echo "OPcache status: Enabled";
|
if ($enabled) {
|
||||||
} else {
|
echo "OPcache status: Enabled";
|
||||||
echo "OPcache status: Disabled";
|
} else {
|
||||||
}
|
echo "OPcache status: Disabled";
|
||||||
exit(0);
|
}
|
||||||
}
|
exit(0);
|
||||||
|
|
||||||
// Format the full response (original functionality)
|
case '--summary':
|
||||||
$response = [
|
// Summary: Basic info + memory usage + key stats
|
||||||
'status' => 'success',
|
$response = [
|
||||||
'data' => [
|
'status' => 'success',
|
||||||
'enabled' => $config['directives']['opcache.enable'],
|
'summary' => [
|
||||||
'memory_usage' => [
|
'enabled' => $config['directives']['opcache.enable'],
|
||||||
'used' => $status['memory_usage']['used_memory'],
|
'memory_usage' => [
|
||||||
'free' => $status['memory_usage']['free_memory'],
|
'used_mb' => round($status['memory_usage']['used_memory'] / 1024 / 1024, 2),
|
||||||
'wasted' => $status['memory_usage']['wasted_memory'],
|
'free_mb' => round($status['memory_usage']['free_memory'] / 1024 / 1024, 2),
|
||||||
'current_wasted_percentage' => $status['memory_usage']['current_wasted_percentage']
|
'wasted_mb' => round($status['memory_usage']['wasted_memory'] / 1024 / 1024, 2),
|
||||||
],
|
'total_mb' => round(($status['memory_usage']['used_memory'] + $status['memory_usage']['free_memory']) / 1024 / 1024, 2),
|
||||||
'interned_strings_usage' => [
|
'wasted_percentage' => $status['memory_usage']['current_wasted_percentage']
|
||||||
'buffer_size' => $status['interned_strings_usage']['buffer_size'],
|
],
|
||||||
'used_memory' => $status['interned_strings_usage']['used_memory'],
|
'cached_scripts' => $status['opcache_statistics']['num_cached_scripts'],
|
||||||
'free_memory' => $status['interned_strings_usage']['free_memory'],
|
'hit_rate' => round($status['opcache_statistics']['opcache_hit_rate'], 2) . '%',
|
||||||
'number_of_strings' => $status['interned_strings_usage']['number_of_strings']
|
'interned_strings' => [
|
||||||
],
|
'count' => $status['interned_strings_usage']['number_of_strings'],
|
||||||
'opcache_statistics' => [
|
'used_mb' => round($status['interned_strings_usage']['used_memory'] / 1024 / 1024, 2),
|
||||||
'num_cached_scripts' => $status['opcache_statistics']['num_cached_scripts'],
|
'buffer_mb' => round($status['interned_strings_usage']['buffer_size'] / 1024 / 1024, 2)
|
||||||
'num_cached_keys' => $status['opcache_statistics']['num_cached_keys'],
|
]
|
||||||
'max_cached_keys' => $status['opcache_statistics']['max_cached_keys'],
|
]
|
||||||
'hits' => $status['opcache_statistics']['hits'],
|
];
|
||||||
'misses' => $status['opcache_statistics']['misses'],
|
echo json_encode($response, JSON_PRETTY_PRINT);
|
||||||
'blacklist_misses' => $status['opcache_statistics']['blacklist_misses'],
|
break;
|
||||||
'blacklist_miss_ratio' => $status['opcache_statistics']['blacklist_miss_ratio'],
|
|
||||||
'opcache_hit_rate' => $status['opcache_statistics']['opcache_hit_rate']
|
case '--statistics':
|
||||||
],
|
// Statistics: Detailed performance metrics
|
||||||
'configuration' => [
|
$response = [
|
||||||
'directives' => $config['directives']
|
'status' => 'success',
|
||||||
]
|
'statistics' => [
|
||||||
]
|
'cache_performance' => [
|
||||||
];
|
'hits' => $status['opcache_statistics']['hits'],
|
||||||
|
'misses' => $status['opcache_statistics']['misses'],
|
||||||
echo json_encode($response, JSON_PRETTY_PRINT);
|
'hit_rate' => round($status['opcache_statistics']['opcache_hit_rate'], 2) . '%',
|
||||||
|
'blacklist_misses' => $status['opcache_statistics']['blacklist_misses'],
|
||||||
|
'blacklist_miss_ratio' => $status['opcache_statistics']['blacklist_miss_ratio']
|
||||||
|
],
|
||||||
|
'cache_usage' => [
|
||||||
|
'cached_scripts' => $status['opcache_statistics']['num_cached_scripts'],
|
||||||
|
'cached_keys' => $status['opcache_statistics']['num_cached_keys'],
|
||||||
|
'max_cached_keys' => $status['opcache_statistics']['max_cached_keys'],
|
||||||
|
'key_usage_percentage' => round(($status['opcache_statistics']['num_cached_keys'] / $status['opcache_statistics']['max_cached_keys']) * 100, 2) . '%'
|
||||||
|
],
|
||||||
|
'memory_details' => [
|
||||||
|
'used_memory' => $status['memory_usage']['used_memory'],
|
||||||
|
'free_memory' => $status['memory_usage']['free_memory'],
|
||||||
|
'wasted_memory' => $status['memory_usage']['wasted_memory'],
|
||||||
|
'current_wasted_percentage' => $status['memory_usage']['current_wasted_percentage']
|
||||||
|
],
|
||||||
|
'restart_info' => [
|
||||||
|
'restart_pending' => $status['restart_pending'] ?? false,
|
||||||
|
'restart_in_progress' => $status['restart_in_progress'] ?? false
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
echo json_encode($response, JSON_PRETTY_PRINT);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '--settings':
|
||||||
|
// Settings: Configuration directives only
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'settings' => [
|
||||||
|
'core_settings' => [
|
||||||
|
'opcache.enable' => $config['directives']['opcache.enable'],
|
||||||
|
'opcache.enable_cli' => $config['directives']['opcache.enable_cli'],
|
||||||
|
'opcache.memory_consumption' => $config['directives']['opcache.memory_consumption'],
|
||||||
|
'opcache.interned_strings_buffer' => $config['directives']['opcache.interned_strings_buffer'],
|
||||||
|
'opcache.max_accelerated_files' => $config['directives']['opcache.max_accelerated_files'],
|
||||||
|
'opcache.revalidate_freq' => $config['directives']['opcache.revalidate_freq']
|
||||||
|
],
|
||||||
|
'performance_settings' => [
|
||||||
|
'opcache.validate_timestamps' => $config['directives']['opcache.validate_timestamps'],
|
||||||
|
'opcache.max_wasted_percentage' => $config['directives']['opcache.max_wasted_percentage'],
|
||||||
|
'opcache.force_restart_timeout' => $config['directives']['opcache.force_restart_timeout'],
|
||||||
|
'opcache.optimization_level' => $config['directives']['opcache.optimization_level']
|
||||||
|
],
|
||||||
|
'advanced_settings' => [
|
||||||
|
'opcache.save_comments' => $config['directives']['opcache.save_comments'],
|
||||||
|
'opcache.enable_file_override' => $config['directives']['opcache.enable_file_override'],
|
||||||
|
'opcache.file_update_protection' => $config['directives']['opcache.file_update_protection'],
|
||||||
|
'opcache.huge_code_pages' => $config['directives']['opcache.huge_code_pages']
|
||||||
|
],
|
||||||
|
'jit_settings' => [
|
||||||
|
'opcache.jit' => $config['directives']['opcache.jit'],
|
||||||
|
'opcache.jit_buffer_size' => $config['directives']['opcache.jit_buffer_size'],
|
||||||
|
'opcache.jit_debug' => $config['directives']['opcache.jit_debug']
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
echo json_encode($response, JSON_PRETTY_PRINT);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Full response (original functionality)
|
||||||
|
$response = [
|
||||||
|
'status' => 'success',
|
||||||
|
'data' => [
|
||||||
|
'enabled' => $config['directives']['opcache.enable'],
|
||||||
|
'memory_usage' => [
|
||||||
|
'used' => $status['memory_usage']['used_memory'],
|
||||||
|
'free' => $status['memory_usage']['free_memory'],
|
||||||
|
'wasted' => $status['memory_usage']['wasted_memory'],
|
||||||
|
'current_wasted_percentage' => $status['memory_usage']['current_wasted_percentage']
|
||||||
|
],
|
||||||
|
'interned_strings_usage' => [
|
||||||
|
'buffer_size' => $status['interned_strings_usage']['buffer_size'],
|
||||||
|
'used_memory' => $status['interned_strings_usage']['used_memory'],
|
||||||
|
'free_memory' => $status['interned_strings_usage']['free_memory'],
|
||||||
|
'number_of_strings' => $status['interned_strings_usage']['number_of_strings']
|
||||||
|
],
|
||||||
|
'opcache_statistics' => [
|
||||||
|
'num_cached_scripts' => $status['opcache_statistics']['num_cached_scripts'],
|
||||||
|
'num_cached_keys' => $status['opcache_statistics']['num_cached_keys'],
|
||||||
|
'max_cached_keys' => $status['opcache_statistics']['max_cached_keys'],
|
||||||
|
'hits' => $status['opcache_statistics']['hits'],
|
||||||
|
'misses' => $status['opcache_statistics']['misses'],
|
||||||
|
'blacklist_misses' => $status['opcache_statistics']['blacklist_misses'],
|
||||||
|
'blacklist_miss_ratio' => $status['opcache_statistics']['blacklist_miss_ratio'],
|
||||||
|
'opcache_hit_rate' => $status['opcache_statistics']['opcache_hit_rate']
|
||||||
|
],
|
||||||
|
'configuration' => [
|
||||||
|
'directives' => $config['directives']
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
echo json_encode($response, JSON_PRETTY_PRINT);
|
||||||
|
break;
|
||||||
|
}
|
Loading…
Reference in New Issue