mb-admin/scripts/check_opcache.php

31 lines
987 B
PHP
Raw Normal View History

2025-06-13 17:17:12 +00:00
<?php
if (!extension_loaded('Zend OPcache')) {
echo json_encode(['status' => 'not_installed']);
exit(1);
}
if (!ini_get('opcache.enable')) {
echo json_encode(['status' => 'disabled']);
exit(1);
}
$status = opcache_get_status(false);
if ($status === false) {
echo json_encode(['status' => 'error', 'message' => 'Cannot retrieve OPCache status']);
exit(1);
}
echo json_encode([
'status' => 'enabled',
'enabled' => $status['opcache_enabled'],
'memory_usage' => [
'used' => round($status['memory_usage']['used_memory'] / 1024 / 1024, 2),
'free' => round($status['memory_usage']['free_memory'] / 1024 / 1024, 2),
'wasted' => round($status['memory_usage']['wasted_memory'] / 1024 / 1024, 2)
],
'statistics' => [
'hits' => $status['opcache_statistics']['hits'],
'misses' => $status['opcache_statistics']['misses'],
'hit_rate' => round($status['opcache_statistics']['opcache_hit_rate'], 2)
]
]);