How the Zend Engine Works
Trace PHP from source to opcodes to execution.
Inside the Engine
PHP is not interpreted line-by-line from source. The Zend Engine compiles your script into an intermediate representation called opcodes, then a virtual machine executes them. Understanding this pipeline explains performance, OPcache, and JIT.
This lesson walks source → tokens → AST → opcodes → VM execution.
The Pipeline
Each request to a PHP file runs through four phases:
- Lexing — source text → tokens (re2c-based scanner)
- Parsing — tokens → Abstract Syntax Tree (Bison grammar)
- Compilation — AST → opcode array (op_array)
- Execution — the Zend VM walks the opcodes
Without OPcache, the first three phases repeat on every request.