PHP will go through two main stages when it starts to execute:
The start phase before processing the request
The end stage after the request
The start phase has two processes:
The first procedure is the module initialization phase (MINIT), which is performed only once throughout the SAPI life cycle (for example, throughout the life cycle of Apache startup or during the entire execution of a command-line program).
The second process is the module activation phase (RINIT), which occurs during the request phase, such as requesting a page through a URL, and module activation before each request (Rinit request starts). For example, if PHP registers some extensions, it will call back the Minit function of all modules during the Minit phase. Modules can perform some initialization work at this stage, such as registering constants, defining classes used by modules, and so on.
The module implements these callback functions by following a macro when implemented:
Php_minit_function (myphpextension) { //Register constants or class initialization operations return SUCCESS;}
After the request arrives, PHP initializes the basic environment for executing the script, such as creating an execution environment, including a symbol table that holds the variable name and value contents of the PHP runtime, and a symbol table for all current functions and information such as classes. PHP then invokes all of the module's Rinit functions, and at this stage each module can perform some related operations, and the module's Rinit function is similar to the Minit callback function:
Php_rinit_function (myphpextension) { ///For example, record the request start time //And then record the end time at the end of the request. So we can record the time it takes to process the request. return SUCCESS;}
After the request has been processed, the end stage is reached, and the general script executes to the end, or by calling the exit () or Die () function, PHP will go to the end stage. And the beginning of the corresponding, the end stage is divided into two links, one at the end of the request to deactivate the module (Rshutdown, corresponding to Rinit), one at the end of the SAPI life cycle (Web server exit or command line script completion exit) when the module is closed (Mshutdown, Corresponds to Minit).
Php_rshutdown_function (myphpextension) { //For example, record the request end time and write the corresponding information to the date to the file. return SUCCESS;}