PHP kernel exploration-start and end of a request: MINIT and RINIT, RSHUTDOWN, and mshutdown php will go through two main phases after execution:
Start phase before Request processing
End stage after request
The start stage has two processes:
The first process is the module initialization phase (MINIT). during The SAPI lifecycle (for example, the entire lifecycle after Apache is started or the entire execution process of the command line program ), this process is only performed once.
The second process is the module activation phase (RINIT), which occurs in the request phase. for example, if a page is requested through a url, the module is activated before each request (RINIT request starts ). For example, if PHP registers some extension modules, the MINIT function of all modules will be called back in the MINIT phase. The module can perform initialization at this stage, such as registering constants and defining classes used by the module.
The module can use the following macro to implement these callback functions:
PHP_MINIT_FUNCTION (myphpextension) {// registers constants, classes, and other initialization operations return SUCCESS ;}
After the request arrives, PHP initializes the basic environment for executing the script, for example, creating an execution environment, including a symbol table that saves the variable name and value content during the PHP running process, symbol table for all current functions, classes, and other information. PHP then calls the RINIT function of all modules. at this stage, each module can also perform some related operations. the RINIT function of the module is similar to the MINIT callback function:
PHP_RINIT_FUNCTION (myphpextension) {// for example, record the request start time // then record the end time at the request end. In this way, we can record the time it took to process the request. return SUCCESS ;}
After the request is processed, it enters the end stage. generally, PHP enters the end stage after the script is executed to the end or by calling the exit () or die () function. The end stage corresponds to the start stage. the end stage is also divided into two steps: one is to stop the module (RSHUTDOWN, corresponding to RINIT) after the end of the request ), when the SAPI lifecycle ends (the Web server exits or the command line script exits), the MSHUTDOWN module (corresponding to MINIT) is disabled ).
PHP_RSHUTDOWN_FUNCTION (myphpextension) {// for example, record the request end time, and write the relevant information to the file on a daily basis. Return SUCCESS ;}