Skip to content

Instantly share code, notes, and snippets.

@defmans7
Created April 24, 2025 01:01
Show Gist options
  • Save defmans7/f812d738e4270c181687accd1bf20d59 to your computer and use it in GitHub Desktop.
Save defmans7/f812d738e4270c181687accd1bf20d59 to your computer and use it in GitHub Desktop.
Check if Opcache is enabled and show some stats
<?php
header('Content-Type: text/plain');
echo "PHP Version: " . phpversion() . "\n\n";
echo "OPCache Enabled: " . (opcache_get_status() ? "Yes" : "No") . "\n\n";
if (opcache_get_status()) {
$status = opcache_get_status();
$config = opcache_get_configuration();
echo "Memory Usage: " . round($status['memory_usage']['used_memory'] / (1024*1024), 2) . "MB / " .
($config['directives']['opcache.memory_consumption']) . "MB\n";
echo "Hit Rate: " . $status['opcache_statistics']['opcache_hit_rate'] . "%\n";
echo "Cached Scripts: " . $status['opcache_statistics']['num_cached_scripts'] . " / " .
$config['directives']['opcache.max_accelerated_files'] . "\n";
if (isset($status['jit'])) {
echo "\nJIT Enabled: Yes\n";
echo "JIT Buffer Used: " . round($status['jit']['buffer_used'] / (1024*1024), 2) . "MB / " .
round($status['jit']['buffer_size'] / (1024*1024), 2) . "MB\n";
} else {
echo "\nJIT Enabled: No\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment