Start and end of a PHP request: MINIT, RINIT, RSHUTDOWN, and MSHUTDOWN

Source: Internet
Author: User
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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.