PHP 8 interview question · Most asked
What happens to an HTTP request in a PHP-FPM application, and what does 'shared nothing' mean?
Summary
nginx passes the request to PHP-FPM over FastCGI; the master assigns it to an idle worker process; the worker runs the entry script (public/index.php) from the top: autoloading, framework bootstrap, routing, controller, response; then all request memory (variables, objects, static properties) is discarded. Nothing in application memory survives to the next request, only OPcache's compiled code, caches, sessions and databases.
Longer Answer
Each worker handles one request at a time, so capacity is workers divided by request time: slow outbound calls exhaust the pool (502/504) even when CPU is idle. Long-running runtimes (Octane, RoadRunner, FrankenPHP worker mode, Swoole) avoid repeated bootstrap but give up shared-nothing isolation, so request state can leak between requests.
Key Points
- FastCGI → worker → script runs from the top.
- All request memory discarded afterwards.
- One request per worker; capacity = workers ÷ time.
- Long-running runtimes trade isolation for speed.
Deep dive: Request Lifecycle course: PHP-FPM and the Shared-Nothing Model
Explanation
What interviewers look for
Understanding the per-request bootstrap and the capacity model.
More most-asked PHP 8 questions
- How should passwords be stored in PHP?
- What are the most important features introduced in PHP 8.0?
- What are named arguments and what are their benefits and risks?
- What is constructor property promotion?
- How does `match` differ from `switch`?
- What are union types in PHP 8 and how do you use them?
- What are enums in PHP 8.1? Explain pure vs backed enums.
- Explain readonly properties (8.1) and readonly classes (8.2).