0Pricing
PHP Academy · Lesson

OPcache and JIT Compilation

Speed up PHP with bytecode caching and JIT.

Caching the Compile

OPcache stores compiled opcodes in shared memory so PHP skips lexing, parsing, and compiling on every request. On top of that, JIT (since PHP 8.0) compiles hot opcodes to native machine code. Together they're the backbone of PHP performance.

This lesson covers configuring OPcache, preloading, and tuning JIT.

What OPcache Does

The compiled op_array for each file is cached in a shared-memory segment used by all FPM workers. A request that hits the cache reuses opcodes directly. OPcache also runs an optimizer (constant folding, dead-code elimination, opcode fusion) the first time it compiles a file.

; Core OPcache config (php.ini)
opcache.enable = 1
opcache.memory_consumption = 256      ; MB of shared memory
opcache.interned_strings_buffer = 16  ; MB for interned strings
opcache.max_accelerated_files = 20000 ; cap on cached scripts

All lessons in this course

  1. How the Zend Engine Works
  2. Memory Management and Garbage Collection
  3. OPcache and JIT Compilation
  4. Writing a Basic PHP Extension in C
← Back to PHP Academy