PHP 8.0 shipped a JIT compiler that attracted significant attention at release but has a narrow effective use case in production web environments. Understanding when JIT actually moves benchmark numbers — and why it usually does not on a standard LAMP or FPM-backed application — saves you from enabling an option that consumes memory and adds startup overhead for no observable gain. This article covers JIT internals, the workload profile it benefits, the configuration knobs, and a measurement methodology that produces trustworthy results.
How to verify
# check JIT is compiled in and current status
php -i | grep -E 'jit|opcache.jit'
# runtime JIT status (requires opcache enabled)
php -r 'print_r(opcache_get_status(false)["jit"] ?? ["jit_disabled"]);'
# check current jit_buffer_size setting
php -i | grep 'opcache.jit_buffer_size'
# simple benchmark: math-heavy workload with and without JIT
php -d opcache.jit_buffer_size=0 bench-math.php
php -d opcache.jit_buffer_size=128M -d opcache.jit=tracing bench-math.php
# FPM pool — confirm JIT settings in effect
sudo php-fpm8.3 -tt 2>&1 | grep -i jit
If jit_disabled appears in the opcache_get_status() output, either jit_buffer_size is zero or OPcache itself is disabled. JIT cannot function without OPcache.
What’s happening
PHP’s JIT operates in two modes: function (opcache.jit=1205) and tracing (opcache.jit=1255). Function mode compiles whole PHP functions to native machine code the first time they are called. Tracing mode monitors hot loops and compiles the traced path — narrower scope but higher optimization potential for tight numeric loops.
The fundamental constraint is where time is spent in a typical PHP web request. A Laravel or Symfony application processing an HTTP request spends roughly 5–15% of wall time in PHP bytecode execution. The remainder is in database I/O, Redis operations, filesystem reads, and extension code already written in C (PDO, mbstring, json_encode). JIT only accelerates the bytecode execution portion. Compressing 10% of 100ms down to 5ms saves 5ms — unmeasurable in production noise.
Workloads where JIT produces meaningful gains share a different profile: sustained CPU computation with minimal I/O. Number crunching (FFT, image convolution, CSV aggregation in PHP), parser implementations, recursive mathematical functions, and ML inference written in pure PHP all benefit from 20–50% speedups. If your PHP process is waiting on the network or disk more than it computes, JIT will not help.
JIT also interacts with OPcache memory in two ways: jit_buffer_size allocates a separate native code segment (not drawn from memory_consumption), and JIT deoptimization generates deoptimized bytecode stubs that consume opcache memory. On multi-tenant hosts where memory is a constraint, this cost is real even when JIT provides no throughput benefit.
The procedure
For a standard web application (likely outcome: no benefit)
-
Leave JIT disabled in the default config:
opcache.jit_buffer_size=0This is the correct default for most PHP-FPM web applications. Do not enable JIT to “be safe” — it costs memory with no upside on I/O-bound code.
-
If you want to verify empirically, run a load test with and without JIT:
# disable JIT, record baseline sudo sed -i 's/^opcache.jit_buffer_size=.*/opcache.jit_buffer_size=0/' \ /etc/php/8.3/fpm/conf.d/20-opcache.ini sudo systemctl reload php8.3-fpm wrk -t8 -c200 -d60s https://app.example.com/api/health | tail -5 # enable JIT tracing, record result sudo sed -i 's/^opcache.jit_buffer_size=.*/opcache.jit_buffer_size=128M/' \ /etc/php/8.3/fpm/conf.d/20-opcache.ini sudo sed -i 's/^;opcache.jit=.*/opcache.jit=tracing/' \ /etc/php/8.3/fpm/conf.d/20-opcache.ini sudo systemctl reload php8.3-fpm wrk -t8 -c200 -d60s https://app.example.com/api/health | tail -5If throughput is within noise (±3%), disable JIT and reclaim the buffer memory.
For a CPU-bound workload (image processing, data pipeline, CLI)
-
Enable tracing JIT with a buffer sized for your working set:
; /etc/php/8.3/cli/conf.d/20-opcache.ini -- CLI override only opcache.enable_cli=1 opcache.jit_buffer_size=256M opcache.jit=tracingIsolating JIT to the CLI ini means FPM web workers are unaffected.
-
Tune
jit_buffer_sizestarting at 64 MB and increase until thejit.buffer_sizemetric inopcache_get_status()["jit"]stops showing buffer overflows:<?php $jit = opcache_get_status(false)['jit']; echo "buffer used: {$jit['buffer_size']} / {$jit['buffer_free']}\n"; -
For functions you want to force JIT regardless of the tracing threshold, use the
#[JIT]attribute (PHP 8.1+) oropcache.jit_hot_functo lower the hot function threshold:opcache.jit_hot_func=5 ; compile after 5 calls instead of default 127 opcache.jit_hot_loop=5 -
Monitor for JIT deoptimization (type guard failures) by checking the
opt_misscounter. High opt_miss means the JIT is compiling optimistic paths that keep failing:print_r(opcache_get_status(false)['jit']); // look at: jit_compiled, jit_opt_miss
Common pitfalls
-
Enabling JIT on shared PHP.ini. Any
opcache.jit_buffer_size> 0 in the globalphp.iniallocates the buffer for every FPM pool and CLI invocation. On a host with 10 pools andjit_buffer_size=128M, that is 1.28 GB of reserved virtual address space. Confine JIT changes to the pool or CLI ini that actually benefits. -
JIT requires OPcache. If
opcache.enable=0or the opcache extension is not loaded, JIT is silently unavailable.opcache_get_status(false)will return false rather than the JIT subarray. -
Tracing mode and fiber/coroutine code. PHP 8.1 Fibers and async libraries (Amphp, ReactPHP) may produce unexpected deoptimizations under tracing JIT because the execution graph switches contexts. Test explicitly before enabling on async workloads.
-
JIT output differs between PHP minor versions. The
opcache.jitnumeric values (1205,1255) changed semantics in PHP 8.1. In PHP 8.2+ the string aliasesfunctionandtracingare preferred and more stable. Prefer the string form in config files to avoid silent misconfigurations after PHP upgrades. -
No JIT gains on opcache-miss paths. JIT only compiles bytecode that is already cached in OPcache. During the cold cache window after a deploy, JIT provides no benefit. Warm OPcache first (see the companion warm-up article) before expecting JIT to contribute.
JIT is a precision tool: valuable for the right workload, wasteful overhead for the typical one. Stack Harbor’s managed operations practice benchmarks JIT impact per environment before enabling it, and ties the decision to workload profiling data rather than general recommendations.