Lab 09: OPcache & JIT
Step 1: OPcache Fundamentals
<?php
// Check if OPcache is available
if (!function_exists('opcache_get_status')) {
echo "OPcache extension not loaded\n";
echo "Enable with: php -d opcache.enable=1 -d opcache.enable_cli=1 script.php\n";
exit;
}
$status = opcache_get_status(false);
if ($status === false) {
echo "OPcache available but disabled (CLI default)\n";
echo "Enable with: php.ini → opcache.enable_cli=1\n";
} else {
$mem = $status['memory_usage'];
echo "OPcache Status:\n";
echo " Enabled: " . ($status['opcache_enabled'] ? 'yes' : 'no') . "\n";
echo " JIT enabled: " . ($status['jit']['enabled'] ? 'yes' : 'no') . "\n";
echo " Used memory: " . number_format($mem['used_memory'] / 1024 / 1024, 2) . " MB\n";
echo " Free memory: " . number_format($mem['free_memory'] / 1024 / 1024, 2) . " MB\n";
echo " Cached files: " . $status['opcache_statistics']['num_cached_scripts'] . "\n";
echo " Hit rate: " . round($status['opcache_statistics']['opcache_hit_rate'], 2) . "%\n";
}Step 2: OPcache Configuration Reference
Step 3: JIT Modes Explained
Step 4: CPU Benchmark — Fibonacci
Step 5: Tight Loop Benchmark
Step 6: OPcache Preloading Concept
Step 7: OPcache Best Practices
Step 8: Capstone — Profiling Suite
Summary
Feature
Config/Function
Notes
Last updated
