PHP 8 interview question · Most asked

How does the PHP 8 JIT work and when does it improve performance?

Create a free account to save this page, take notes and track your progress. Sign in

Summary

The JIT compiles hot opcodes to native machine code at runtime on top of OPcache. It greatly speeds up CPU-bound work (math, image processing), but gives little benefit to typical I/O-bound web apps.

Longer Answer

PHP normally compiles source to opcodes (cached by OPcache) that the Zend VM interprets. The JIT, built on DynASM, adds a further step: it compiles frequently executed code to native machine code. The tracing JIT (opcache.jit=tracing, default mode when enabled) profiles hot loops and functions; the function JIT compiles whole functions.

Most web requests spend their time waiting on databases, network and I/O, so benchmarks like WordPress or Laravel see small gains. Fractals, ML in PHP and long-running workers benefit far more. PHP 8.4 moved to a new IR-based JIT backend and changed the configuration defaults (opcache.jit=disable with a non-zero buffer).

Code Example

; php.ini
opcache.enable=1
opcache.enable_cli=1
opcache.jit_buffer_size=128M
opcache.jit=tracing

Key Points

  • Requires OPcache; enable via opcache.jit_buffer_size and opcache.jit
  • Tracing JIT targets hot paths
  • Large gains for CPU-bound code, small for I/O-bound apps
  • Measure with real workloads before enabling in production

Explanation

What interviewers look for

Nuance: why JIT doesn't matter much for CRUD apps, and that OPcache (not JIT) is the big production win.

Common mistakes

  • Enabling JIT without OPcache
  • Promising 3x speedups for a typical Laravel app

Follow-up questions

  • What does OPcache preloading do?
  • How would you benchmark JIT impact?

More most-asked PHP 8 questions

← All PHP 8 questions

Was this page helpful?