Created
April 24, 2025 00:59
-
-
Save defmans7/32f184a554ffdb3a5d588feafebfefd5 to your computer and use it in GitHub Desktop.
Verify and check PHP Opcache jit is working
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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