The life cycle of PHP is detailed

Source: Internet
Author: User
Tags filter command line resource sapi

Life Cycle of PHP

In a common webserver environment, you cannot start the PHP interpreter directly; Typically, you start Apache or other webserver, and they load the script that the PHP process needs to handle (the requested. PHP document).

Everything starts from SAPI.

Although it may look different, the CLI behaves in the same way as the web. Typing the PHP command at the command line will start command line SAPI, which is actually like a mini version webserver designed for service order requests. When the script is finished, the mini Php-webserver terminates and returns control to the shell.

Start and end

The initiation and termination processes here are divided into two separate start-up phases and two separate termination phases. A cycle is used for initialization of the structure and values required by the PHP interpreter as a whole, and they persist in the SAPI lifecycle. The other only serves a single page request with a short life cycle.

Initialize startup PHP calls each extended Minit (module initialization) method before all requests occur. Here, the extension may define constants, define classes, register resources, streams, filter processors, and all the resources that will be used by the requested script. All of these have an attribute, that is, they are designed to exist across all requests, or they can be called "persistent."

The common Minit methods are as follows:

/* Initialize myextension module * This will happen immediately after SAPI is started * * * php_minit_function (myextension) {/* Global: 12th Chapter */#ifdef ZTS ts_allocate_id (&myextension_globals_id, sizeof (Php_myextension_globals), (Ts_allocate_ctor) my  
Extension_globals_ctor, (Ts_allocate_dtor) myextension_globals_dtor);  
#else myextension_globals_ctor (&myextension_globals tsrmls_cc);  
      
      
    #endif/* register_ini_entries () point to a global structure, we will be in the 13th "INI settings" to learn * * register_ini_entries (); /* equivalent to define (' myext_meaning ', 42); * * Register_long_constant ("myext_meaning", Const_cs |  
    Const_persistent); /* equivalent to define (' Myext_foo ', ' Bar '); * * Register_string_constant ("Myext_foo", "Bar", Const_cs |  
      
      
    Const_persistent); /* Resources: 9th Chapter * * * Le_myresource = ZEND_REGISTER_LIST_DESTRUCTORS_EX (Php_myext_myresource_dtor, NULL  
    , "My Resource Type", module_number); Le_myresource_persist = zend_register_list_destructors_ex (NULL, Php_myext_myresource_dtor, "my  
      
      
    Resource Type ", module_number); /* Flow Filter: 16th Chapter */if (failure = = Php_stream_filter_register_factory ("Myfilter", &php_myextensi  
    On_filter_factory tsrmls_cc)) {return failure;  
                   }/* Flow wrapper: 15th Chapter */if (failure = = Php_register_url_stream_wrapper ("Myproto"),  
    &php_myextension_stream_wrapper tsrmls_cc)) {return failure; }/* Automatic global variable: the 12th Chapter */#ifdef zend_engine_2 if (zend_register_auto_global) ("_myextension", sizeof (" _myextension ")-1, NULL tsrmls_cc) = = failure) {return failu  
    RE;  
                                                     } zend_auto_global_disable_jit ("_myextension", sizeof ("_myextension")-1  
TSRMLS_CC); #else if (zend_register_aUto_global ("_myextension", sizeof ("_myextension")-1 tsrmls_cc) = =  
    Failure) {return failure;  
#endif 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.