98 lines
3.4 KiB
PHP
98 lines
3.4 KiB
PHP
<?php
|
|
// Add error reporting
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 1);
|
|
|
|
// Check if running from CLI
|
|
if (php_sapi_name() !== 'cli') {
|
|
echo json_encode(['status' => 'error', 'message' => 'This script must be run from CLI']);
|
|
exit(1);
|
|
}
|
|
|
|
// 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')) {
|
|
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) {
|
|
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) {
|
|
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);
|
|
}
|
|
|
|
// 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' => [
|
|
'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);
|