PHP variable life cycle: PHP source analysis-php life cycle

Source: Internet
Author: User
Tags define end variables return variable

The two most common running modes of PHP are Web mode, CLI mode.
Either way, PHP works the same way as a SAPI run.
1, when we typed the command of PHP in the terminal, it uses the CLI.
It is like a Web server to support PHP to complete this request, the request is completed and then put control over to the terminal.
2, when using Apache as a host, when a request arrives, PHP will support the completion of this request.
The following macros are defined in Main/php.h
#define Php_minit_function Zend_module_startup_d
#define Php_mshutdown_function Zend_module_shutdown_d
#define Php_rinit_function Zend_module_activate_d
#define Php_rshutdown_function Zend_module_deactivate_d
#define Php_minfo_function Zend_module_info_d
#define Php_ginit_function Zend_ginit_function
#define Php_gshutdown_function Zend_gshutdown_function
The corresponding function is
Php_minit_function when initializing module
Php_mshutdown_function run when module is unloaded
Php_rinit_function run when a request is initialized
Php_rshutdown_function run when a request is finished
Php_minfo_function This is the information that sets up this module in Phpinfo
Php_ginit_function initialization of global variables
Php_gshutdown_function when global variables are released
Read a custom extension case fragment:
int minit_time;
Php_minit_function (Test)
{
Minit_time = time (NULL);
return SUCCESS;
}
Php_mshutdown_function (Test)
{
FILE *fp=fopen ("Mshutdown.txt", "A +");
fprintf (FP, "%ld\n", Time (NULL));//Let's see if we're going to append data to this file at the end of each request.
Fclose (FP);
return SUCCESS;
}
int rinit_time;
Php_rinit_function (Test)
{
Rinit_time = time (NULL);
return SUCCESS;
}
Php_rshutdown_function (Test)
{
FILE *fp=fopen ("Rshutdown.txt", "A +");
fprintf (FP, "%ld\n", Time (NULL));//Let's see if we're going to append data to this file at the end of each request.
Fclose (FP);
return SUCCESS;
}
Php_minfo_function (Test)
{
Php_info_print_table_start ()//call Php_write output HTML tag
Php_info_print_table_header (2, "module info", "Enabled"); This article links http://www.cxybl.com/html/wlbc/Php/20121221/35071.html

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.