0PricingLogin
PHP Academy · Lesson

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.

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