PHP Source Learning-life cycle _php Tutorial

Source: Internet
Author: User
Tags call back sapi

After 2 years of PHP, only know the outside, do not know its, not its meaning;

start of everything: SAPI interface

SAPI (server application programming Interface) refers to the specific application programming interface of PHP, PHP scripts to be executed in a number of ways, such as: Through the Web server, command line, can also be embedded in other programs Usually we use a Web server like Apache or Nginx to test a PHP script, or to execute a script at the command line, after the script executes, the Web server answers, the browser displays the response information, or the content is displayed on the terminal.

< span="">< span="">< span="">

1) The module initialization phase (MINIT), which is performed only once during the entire SAPI life cycle (for example, the entire life cycle after Apache boot or the entire execution of a command-line program).

2) Module activation phase (RINIT), the process occurs in the request phase, for example, through a URL request a page, then before the request will be module activation, such as some PHP registered extensions, in the Minit phase will call back all the modules Minit function. The module will perform some initialization work at this stage, such as registering constants, defining the classes used by the module, and so on.

2. Request processing: 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 class information. Then PHP calls all the modules of the Rinit function, at this stage each module can also perform some related operations;

3. End of request: After processing the request to enter the end phase, the general script execution to the end by calling the exit () or Die () function, PHP will enter the end phase, and the beginning of the corresponding, the end stage is divided into two links

1) Deactivate module (Rshutdown, corresponding to Rinit)

2) Close module (Mshutdown, corresponding to Minit) when SAPI end of life cycle (Web server exits or command line execution exits)

  

Single-Process SAPI life cycle

The command-line mode of PHP is a single-process SAPI mode, which is closed after processing one time, the entire processing process only the following links: Start-Request Start-Request shutdown-end SAPI interface implementation has completed its life cycle. Single-Process SAPI life cycle

       

Multi-process SAPI life cycle

In addition to the command line, there is another one of the most processing PHP requests than the Web server, such as apache;apache as a Web server will be a multi-process mode, Apache will fork out after the start of the process, the memory space of each process is independent, Each subprocess goes through the start and end sessions, but the start of each child process is made only after the process fork, and multiple requests may be processed throughout the lifetime of the process. The shutdown phase only occurs when Apache is closed or the process is ended, and between these two phases the request starts with each request-the link to the request shutdown. Multi-process SAPI life cycle.

  

Multithreading SAPI life cycle

Multithreaded mode is similar to a multi-process pattern, where the request is repeated in parallel over the entire life cycle-request shutdown

  

(Reprint please specify Source: Author: Jmol, Weibo: Http://weibo.com/yospace Blog Park: http://www.cnblogs.com/yoainet/)

http://www.bkjia.com/PHPjc/741586.html www.bkjia.com true http://www.bkjia.com/PHPjc/741586.html techarticle After 2 years of PHP, only know the outside, do not know its inside, not its meaning; in learning, the key points are recorded here; the beginning of everything: SAPI interface SAPI (server Application programming Interface) refers to ...

  • 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.