PHP & Zend Engine (50 Qs)•Part 1: Core Language, Execution Lifecycle & Types (1 - 10)
How does the PHP Execution Lifecycle work (SAPI, FastCGI, and PHP-FPM)?
senior LevelLifecycleHTTP & REST APIs
In Simple Words: PHP does not run as a continuous in-memory application server by default. Instead, it follows a Share-Nothing Architecture where each incoming HTTP request executes in an isolated process/thread, initializes state, runs code, and completely destroys all memory on request termination.
Lifecycle Stages:
- Module Init (MINIT): Triggered once when PHP-FPM starts. Loads extensions and registers persistent constants.
- Request Init (RINIT): Triggered for every incoming HTTP request. Allocates request memory pool and initializes
$_GET,$_POST, and$_SERVER. - Execution: The Zend VM executes compiled opcodes.
- Request Shutdown (RSHUTDOWN): Cleans up user-defined objects, runs output buffering flushes, and frees request memory.
- Module Shutdown (MSHUTDOWN): Triggered when PHP-FPM stops.