PHP 8.0 JIT: What It Really Does (and Doesn’t) Do

🌟 Introduction

PHP 8.0 introduced Just-In-Time compilation (JIT) with high expectations. Developers imagined JavaScript-like performance boosts and dreams of CPU-bound PHP games. But what's the real story?

In this article, we’ll:

  • Explain what JIT does

  • Show how to activate it

  • Run benchmarks with and without it

  • Reveal where it truly shines (and where it doesn’t)


🧠 What is JIT?

JIT stands for Just-In-Time Compilation. Unlike traditional interpreters, which parse and execute line-by-line, a JIT-enabled engine compiles parts of the code at runtime into native machine code, which can be executed directly by the CPU.

✨ JIT vs OPCache

FeatureOPCacheJIT
Compiles toZend opcodesNative machine code
WhenOn script loadAt runtime, selectively
Use caseWeb applications (low I/O wait)CPU-heavy tasks (math, loops, etc.)

🔧 How to Enable JIT in PHP 8.0

Make sure you're using PHP 8.0 or later. Then edit your php.ini (often found via php --ini):

opcache.enable=1
opcache.jit_buffer_size=100M
opcache.jit=1255

📄 Meaning of opcache.jit=1255

This config tells PHP to use the tracing JIT with maximum optimization level (function + loop tracing). You can tweak it for different performance profiles:

ValueDescription
1205Function calls only
1255Function + loops (default high level)
0JIT disabled

⚠️ JIT has no effect unless opcache.jit_buffer_size is > 0.

To confirm it works:

php -i | grep JIT

Should show something like:

opcache.jit => 1255 => 1255
opcache.jit_buffer_size => 100M => 100M

🔢 Benchmark Time

Let's look at 3 simple benchmarks.

1. Simple Loop (CPU-bound)

$start = microtime(true);

$sum = 0;
for ($i = 0; $i < 100000000; $i++) {
    $sum += $i;
}

echo "Time: ".(microtime(true) - $start)."s\n";

Results:

EnvironmentTime
PHP 8.0 (no JIT)~2.4 s
PHP 8.0 (JIT)~1.1 s

2. Web API Simulation

// simulate DB call delay// simulate DB call delay\usleep(100);
echo "Hello, world!";

Results:

EnvironmentTime
PHP 8.0 (no JIT)~100 ms
PHP 8.0 (JIT)~100 ms

No gain here—JIT doesn’t help with I/O.

3. Mandelbrot Fractal

// Source: official php-src/bench.php examples

Results:

EnvironmentTime
PHP 8.0 (no JIT)~1.5 s
PHP 8.0 (JIT)~0.6 s

This test is computationally expensive and benefits a lot from JIT.


🫶 Should You Use It?

ScenarioGain with JIT?
Laravel/Symfony Web App❌ Negligible
Heavy scientific computation✅ Significant
CLI scripts with math✅ Moderate
APIs, CRUD, DB apps❌ No impact

In short:

  • Don’t expect miracles for web workloads.

  • Do try it for CLI or intensive math tasks.


📊 Final Thoughts

The JIT engine in PHP 8.0 is a great evolution, especially for non-traditional PHP use cases. It brings PHP closer to compiled language performance for math-heavy scenarios.

But for your typical Laravel or Symfony app? The difference is minimal. If you're running CPU-intensive background jobs, however, go ahead and experiment with JIT—you might be surprised.

📅 Fun fact: The real performance gain for web apps still comes from OPCache, code refactoring, and DB optimizations, not JIT.


Written for OpenSource My Friend — your Laravel and PHP performance playground.

0
Subscribe to my newsletter

Read articles from Jean-Marc Strauven directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jean-Marc Strauven
Jean-Marc Strauven

Jean-Marc (aka Grazulex) is a developer with over 30 years of experience, driven by a passion for learning and exploring new technologies. While PHP is his daily companion, he also enjoys diving into Python, Perl, and even Rust when the mood strikes. Jean-Marc thrives on curiosity, code, and the occasional semicolon. Always eager to evolve, he blends decades of experience with a constant hunger for innovation.