PHP core-lifecycle

Source: Internet
Author: User
Tags sapi
PHP Core---LifeCycle

PHP CORE

PHP core consists of two separate parts, the bottom part is Zend Engine, Ze is responsible for human-readable script parsing into machine-readable tokens, and then in a processing space to execute these tokens,ze while also dealing with memory management, Variable scope and distribution (dispatch) function calls;

The other layer is the PHP core, which is responsible for connecting to the SAPI layer of the binding, SAPI the Server application programming Interface, typically referencing the host environment, such as IIS? Cli? CGI and so on, it also provides a unified control layer for Safe_mode and open_basedir checks, such as the streams layer of connection files and network I/O, with fopen () fread () and Fwriter () methods.


Lifecycles


When SAPI is started in a host environment, such as when/usr/local/apache/bin/apachectl starts, PHP begins to initialize his core subsystem (subsystems), and next, at the end of this launcher, PHP will load the code for each extension (Extension) and the module initialization program that invokes them (module initialization routing, minit), so that every Extension has the opportunity to initialize the internal variables, The allocation of resources, the registration of resource handles, and the registration of their functions in ze, so that when a script calls one of these functions, Ze will know which piece of code to execute.

? ? Next, PHP waits for the SAPI layer to request the execution of a page, in the CGI or CLI SAPI These environments, this is happening immediately and only once, in Apache, IIS or other mature Web server SAPI, He only happens when the remote user requests it, or repeats any number of times, both of which may be concurrent.

no matter how the request arrives, PHP will request ze to set up an environment for the script to run, and then invoke each extended request initialization function ( Request initialization? ( RINIT ) function),? Rinit gives every extension the opportunity to create special environment variables, assign requests for specified resources, and perform other tasks, such as auditing. For example, such as session Extension, in the php.ini file if session.auto_start This parameter is set to 1 (default is 0), the level description allows Automatically starts the session, the rinit will automatically trigger the Session_Start () function of the user space and set the $_session variable beforehand.

Once the request has been initialized, Ze will translate the PHP script into tokens, and finally become the executable opcode (opcodes), how to invoke a extension function in the opcode, then ze will pass the argument to the function, and temporarily surrender control to know that the function is complete.

? When a copy of the script is completed, PHP will invoke each extension request stop function (requestsShutdown) RSHUTDOWN to perform the last cleanup operation. For example, save the session variable to disk. Then Ze will execute a cleanup process, known as garbage collection (garbage collection),? garbage collection can effectively execute a unset () method on each of the previous requests to release the variable.

When this is done, will PHP wait for SAPI's next request or just a terminating operation, with no next request in CGI and CLI Sapis? SAPI will perform the shutdown operation immediately. During the execution of shutdown, will PHP cycle through every extension and call them? Module Shutdown? ( MSHUTDOWN ) functions, this corresponds to the previous Module initialization Routing . After terminating all extension, PHP will eventually shut down to his own core subsystem.


?? From the above we can see,? In the process of a request, ze and PHP core are responsible for the division, PHP core to receive request processing requests, and Ze responsible for PHP script execution.

?

?

?

?

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