Laravel & Ecosystem (50 Qs)•Part 1: Architecture, Service Container & Request Lifecycle (1 - 10)
How does the PHP Execution Lifecycle work (CGI vs FastCGI vs PHP-FPM)?
senior LevelLifecycleDocker & ContainersSystem Design
In Simple Words: PHP traditionally runs in a Share-Nothing Architecture:
- Nginx receives an incoming HTTP request.
- Nginx forwards the request over a Unix Domain Socket to PHP-FPM (FastCGI Process Manager).
- PHP-FPM assigns the request to an idle pre-forked worker process.
- The worker boots the application, executes the PHP script, renders output, and sends the HTTP response back.
- Memory Clean: The worker process wipes all memory and state clean, ready for the next request! Zero memory leaks across requests, but requires bootstrapping the framework on every hit.