mb-admin/scripts/check_opcache.php

55 lines
2.2 KiB
PHP
Raw Normal View History

2025-06-13 17:17:12 +00:00
<?php
2025-06-13 17:23:54 +00:00
// Check if OPCache is enabled
if (!function_exists('opcache_get_status')) {
echo json_encode(['status' => 'error', 'message' => 'OPCache is not installed']);
2025-06-13 17:17:12 +00:00
exit(1);
}
2025-06-13 17:23:54 +00:00
// Get OPCache status
$status = opcache_get_status(false);
if ($status === false) {
echo json_encode(['status' => 'error', 'message' => 'Failed to get OPCache status']);
2025-06-13 17:17:12 +00:00
exit(1);
}
2025-06-13 17:23:54 +00:00
// Get OPCache configuration
$config = opcache_get_configuration();
if ($config === false) {
echo json_encode(['status' => 'error', 'message' => 'Failed to get OPCache configuration']);
2025-06-13 17:17:12 +00:00
exit(1);
}
2025-06-13 17:23:54 +00:00
// Format the response
$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']
]
2025-06-13 17:17:12 +00:00
]
2025-06-13 17:23:54 +00:00
];
echo json_encode($response, JSON_PRETTY_PRINT);