Explain the PHP request lifecycle from the moment a request hits the server to the moment it is terminated.
Last updated
Once per process,
MINIT(module init) registers extensions, constants and classes.MSHUTDOWNreleases them when the process ends.Per request,
RINITpopulates superglobals. The Zend Engine compiles the script to opcodes (cached by OPcache) and executes them.RSHUTDOWNthen runs shutdown functions, flushes output, writes sessions and frees memory.Under FPM the process persists, so module phases run rarely while request phases run on every request.
- https://www.phpinternalsbook.com/php7/extensions_design/php_lifecycle.html
- https://levelup.gitconnected.com/writing-a-tiny-php-extension-what-php-src-looks-like-from-the-outside-b878b31eec68
- https://www.survivethedeepend.com/articles/request-lifecycle-explained-for-php-developers/
- https://medium.com/gitconnected/writing-a-tiny-php-extension-what-php-src-looks-like-from-the-outside-b878b31eec68
- https://engineers.fenrir-inc.com/entry/2022/12/26/113630
- https://wiki.php.net/internals/extensions
- https://medium.com/tech-vibes/tracing-request-lifecycles-in-php-without-external-apms-4ff4c4b7b47b