Home > Article > Backend Development > PHP life cycle and how fpm works
PHP life cycle and the operation mode of fpm (FastCGI Process Manager)
How does PHP change the file in web mode to take effect immediately? Several important points Concept:
● sapi: can be simply understood as a unified interface for the PHP engine to the outside world, allowing PHP to interact with external programs
● Four key points in the life cycle of PHP Call: MINT -> RINT -> RSHUTDOWN -> MSHUTDOWN
● fpm: fastcgi process manager
The process of fpm method is:
fpm interacts with the php process through the sapi interface
1. When fpm starts, it will call the MINT method of each extension to initialize some data (resident in memory)
2. Each request comes, First, RINT will be executed to initialize a single request line
3. Execute the php script (in the absence of cached opcode, the php script here is executed dynamically, so after updating the php script, the new php will be executed. Script, the details will not be described here)
4. Execute the RSHUTDOWN method
5. If you want to stop fpm, you will execute MSHUTDOWN
fpm's processing of each request Steps 2~4 are being executed repeatedly. In the third step, the php script is executed dynamically, because the php script must be executed once every time, and each php script must have a translation of the php file into The opcode process (which is relatively time-consuming) led to the creation of the opcache tool.
opcache
Directly save the PHP translated opcode code tree to the shared memory for direct use, thereby reducing the overhead of translating PHP into opcode every time .
Opcache problem: According to his description, the php file was modified and could not be updated immediately.
Opcache's solution: There is a configuration to set how long it takes to detect whether the file has been updated, so that there is an opportunity to reload the related files in the second step.
Of course, reload fpm directly to achieve the effect of PHP hot update (opcache extension can clear the relevant opcode cache in the fourth step).
Illustration
For more PHP related knowledge, please visit PHP Tutorial!
The above is the detailed content of PHP life cycle and how fpm works. For more information, please follow other related articles on the PHP Chinese website!