PHP Life Cycle Detailed

Source: Internet
Author: User
Tags sapi

SAPI

SAPI (Server application Programming INTERFAC) is a application programming interface (API) provided by the Web Server to Help other developers in extending the Web server capabilities.

SAPI is an application interface (API) that is used to help other developers extend the functionality of the Web server. It abstracts the external conditions and provides a set of fixed and unified interfaces for internal PHP, so that PHP can not be affected by the external environment and maintain its independence.
The common SAPI in PHP are CLI (command line mode, single process), PHP-FPM, CGI, Apache ...
It's a bit like policy mode, using the same interface, but the implementation is slightly different.

PHP Start-up and termination

    • The start phase before the request:

      • Minit: module initialization phase. Initialize some extensions, constants, classes, resources, and all the things that are used by PHP scripts. (resident memory, can be used by all requests.) )

      • PRINT: module activation phase. PHP invokes the Rinit function of all modules, and at this stage each module can perform some related operations, such as initializing 本次请求 the variables used.

    • The end stage after the request:

      • Rshutdown: This page request completed, or by the user to Die (exit), then PHP will start the Recycle program, recycling the resources used for this request. This time, all the Rshutdown (commonly called request Shutdown) methods that have been loaded are executed, and the extension can take advantage of a list of variables in the kernel, among other things. As soon as PHP executes all the extended Rshutdown methods, it frees up all the resources that the request used, such as all variables in the variable table, all the memory requested in the request.

      • mshutdown:php executes all extended mshutdown to release resources.

The life cycle of PHP

1. Single-Process SAPI life cycle (cli/cgi)

2. Multi-process SAPI life cycle (APACHE2)

3. Multi-threaded SAPI life cycle

4.Embed

Embed SAPI is a special SAPI that allows you to invoke the functions provided by php/ze in the C + + language. (not quite understand, look at it tomorrow!) http://www.laruence.com/2008/09/23/539.html)

Review

Check the lifecycle of PHP and the entire process of PHP execution. And how to communicate through SAPI and PHP modules.
(The picture is basically from the reference link over there, standing on the shoulders of predecessors.) )

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.