Skip to content

Instantly share code, notes, and snippets.

@defmans7
Created April 24, 2025 00:59
Show Gist options
  • Save defmans7/32f184a554ffdb3a5d588feafebfefd5 to your computer and use it in GitHub Desktop.
Save defmans7/32f184a554ffdb3a5d588feafebfefd5 to your computer and use it in GitHub Desktop.
Verify and check PHP Opcache jit is working
<?php
// Force JIT to engage with a computationally intensive loop
function test_jit() {
$start = microtime(true);
$sum = 0;
for ($i = 0; $i < 10000000; $i++) {
$sum += $i * 0.01;
}
$end = microtime(true);
return [
'sum' => $sum,
'time' => ($end - $start),
'jit_status' => function_exists('opcache_get_status') ? opcache_get_status(false)['jit'] : 'N/A'
];
}
// Run the test
$result = test_jit();
// Output results
header('Content-Type: text/plain');
echo "JIT Test Results\n";
echo "---------------\n";
echo "Sum: " . $result['sum'] . "\n";
echo "Time: " . number_format($result['time'], 4) . " seconds\n\n";
if (is_array($result['jit_status'])) {
echo "JIT Status:\n";
echo "Buffer Size: " . ($result['jit_status']['buffer_size'] / 1024 / 1024) . "MB\n";
echo "Buffer Used: " . ($result['jit_status']['buffer_used'] / 1024 / 1024) . "MB\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment