There are two types of data sources in PHP:
- 1. From the Code
For variables in the code (that is, the direct amount), the variable assignment/assignment is active in the executor at compile time, and is destroyed during the request shutdown period. For these variables, the value of this part of the variable is cached by using APC for opcode caching.
And for variables from the outside, variable allocation/assignment in the compiler, before the execution period, in the request shutdown period was destroyed, for these variables, using APC for opcode cache, is not cached.
Focus today on one part of the next external variable, the entire lifecycle of the data from get.
Suppose the following request arrives:
And, in the index.php:
- <?php
- $name =
There are two types of data sources in PHP:
- 1. From the Code
For variables in the code (that is, the direct amount), the variable assignment/assignment is active in the executor at compile time, and is destroyed during the request shutdown period. For these variables, the value of this part of the variable is cached by using APC for opcode caching.
And for variables from the outside, variable allocation/assignment in the compiler, before the execution period, in the request shutdown period was destroyed, for these variables, using APC for opcode cache, is not cached.
Focus today on one part of the next external variable, the entire lifecycle of the data from get.
Suppose the following request arrives:
And, in the index.php:
___fckpd___2
We know that in the final execution period, the $_get array must contain the following fragment:
There are two types of data sources in PHP:
- 1. From the Code
For variables in the code (that is, the direct amount), the variable assignment/assignment is active in the executor at compile time, and is destroyed during the request shutdown period. For these variables, the value of this part of the variable is cached by using APC for opcode caching.
And for variables from the outside, variable allocation/assignment in the compiler, before the execution period, in the request shutdown period was destroyed, for these variables, using APC for opcode cache, is not cached.
Focus today on one part of the next external variable, the entire lifecycle of the data from get.
Suppose the following request arrives:
And, in the index.php:
- <?php
- $name =
There are two types of data sources in PHP:
- 1. From the Code
For variables in the code (that is, the direct amount), the variable assignment/assignment is active in the executor at compile time, and is destroyed during the request shutdown period. For these variables, the value of this part of the variable is cached by using APC for opcode caching.
And for variables from the outside, variable allocation/assignment in the compiler, before the execution period, in the request shutdown period was destroyed, for these variables, using APC for opcode cache, is not cached.
Focus today on one part of the next external variable, the entire lifecycle of the data from get.
Suppose the following request arrives:
And, in the index.php:
___fckpd___2
We know that in the final execution period, the $_get array must contain the following fragment:
___fckpd___3
So, let's focus today on how Query string is built into _get arrays (for the generation of Get variables, please read my previous article: "PHP's Get/post and other large variable generation process"):
At the time of the request, the Php_request_startup (defined in MAIN.C) is invoked to do the initialization of the scene. Include setting time-out values in this procedure, calling the request initialization function for each module. Of course, we also care about creating variable environments.
Php_hash_environment according to the Variables_order in php.ini to initialize each predefined large variable sequentially, then for $_get:
- ...
- case ' g ':
- case ' G ':
- if (!_gpc_flags[2]) {
- sapi_module.treat_data (parse_get, NULL, null TSRMLS_CC);
- _gpc_flags[2] = 1;
- if (PG (register_globals)) {
- php_autoglobal_merge (&EG ( symbol_table),
- z_arrval_p (PG (http_globals) [track_vars_get]) tsrmls_cc);
- }
- }
- break;
In general, this logic, first through the treat_data to generate variable hash (PG (http_globals) [Track_vars_get]), if you open the Auto_register_globals, then the $_ The variables in the get array are added to the symbol table.
Treat_data is a member of the Sapi_module_struct:
- Note: This article is based on the apache2handler approach of SAPI, this startup process and previous articles SAPI
- The principle of the startup process is slightly different, php5 through the registered apache2 Ap_hook_post_config Hook,
- Start PHP when Apache server is started (Php_apache_server_startup, defined in
- SAPI/APACHE2HANDER/SAPI_APACHE2.C), in this function call Sapi_startup start SAPI,
- And then by calling Php_apache2_startup to register SAPI module struct,
- Then invoke Php_module_startup to initialize PHP, which will initialize the Zend engine,
- and fill in the Treat_data member in Zend_module_struct (through Php_startup_sapi_content_types)
Now go back and look at Treat_data (i.e. Php_default_treat_data):
- ....
- if (arg = = Parse_get) {/* Get data */
- C_var = SG (request_info). query_string;
- if (C_var && *c_var) {
- res = (char *) estrdup (C_var);
- Free_buffer = 1;
- } else {
- Free_buffer = 0;
- }
- else if (arg = = Parse_cookie) {/* COOKIE data * *
In the above logic, the res is replicated to Query_string, and the SG (request_info) is a structure representing the current request information, where query_string is in Php_apache_request_ ctor by copying the args in the Apache REQEUST_REC structure.
For the example of this article, Res is now "Name=laruence&career[]=yahoo&career[]=baidu",
To continue in the Treat_data, the following logic is:
- var = php_strtok_r (res, separator, &strtok_buf);
- ...
- while (Var) {
- val = Strchr (var, ' = ');
- if (arg = = Parse_cookie) {
- /* Remove leading spaces from cookie names,
- Needed for Multi-cookie header where; Can be followed by a space * *
- while (Isspace (*var)) {
- var++;
- }
- if (var = val *var = ' ") {
- Goto Next_cookie;
- }
- }
- if (val) {/* have a value */
- int Val_len;
- unsigned int new_val_len;
- *val++ = ' n ';
- Php_url_decode (Var, strlen (Var));
- Val_len = Php_url_decode (Val, strlen (Val));
- val = Estrndup (val, Val_len);
- if (Sapi_module.input_filter (ARG, VAR, &val, Val_len, &new_val_len tsrmls_cc)) {
- Php_register_variable_safe (Var, Val, New_val_len, Array_ptr tsrmls_cc);
- }
- Efree (Val);
- } else {
First, by php_strtok_r the res into a "Key=value" segment based on "&", then the Var and Val are copied as key and value respectively, noting that the Var and Val are php_url_ in this process. Decode.
Finally, add a member named Var value of Php_register_variable_safe to Array_ptr (http_globals) [Track_vars_get], or $_get, at this point.
In this step, our $_get array contains the following members:
- ' Name ' => ' laruence ',
- ' Career ' => array (
- ' Yahoo ', ' Baidu ',
To be continued (the destruction process of the variable) ...
get[' name '];
We know that in the final execution period, the $_get array must contain the following fragment:
___fckpd___3
So, let's focus today on how Query string is built into _get arrays (for the generation of Get variables, please read my previous article: "PHP's Get/post and other large variable generation process"):
At the time of the request, the Php_request_startup (defined in MAIN.C) is invoked to do the initialization of the scene. Include setting time-out values in this procedure, calling the request initialization function for each module. Of course, we also care about creating variable environments.
Php_hash_environment according to the Variables_order in php.ini to initialize each predefined large variable sequentially, then for $_get:
___fckpd___4
In general, this logic, first through the treat_data to generate variable hash (PG (http_globals) [Track_vars_get]), if you open the Auto_register_globals, then the $_ The variables in the get array are added to the symbol table.
Treat_data is a member of the Sapi_module_struct:
___fckpd___5
Now go back and look at Treat_data (i.e. Php_default_treat_data):
___fckpd___6
In the above logic, the res is replicated to Query_string, and the SG (request_info) is a structure representing the current request information, where query_string is in Php_apache_request_ ctor by copying the args in the Apache REQEUST_REC structure.
For the example of this article, Res is now "Name=laruence&career[]=yahoo&career[]=baidu",
To continue in the Treat_data, the following logic is:
___fckpd___7
First, by php_strtok_r the res into a "Key=value" segment based on "&", then the Var and Val are copied as key and value respectively, noting that the Var and Val are php_url_ in this process. Decode.
Finally, add a member named Var value of Php_register_variable_safe to Array_ptr (http_globals) [Track_vars_get], or $_get, at this point.
In this step, our $_get array contains the following members:
___fckpd___8
To be continued (the destruction process of the variable) ...
Get = Array (
- ' Name ' => ' laruence ',
- ' Career ' => array (
- ' Yahoo ', ' Baidu ',
- ),
So, let's focus today on how Query string is built into _get arrays (for the generation of Get variables, please read my previous article: "PHP's Get/post and other large variable generation process"):
At the time of the request, the Php_request_startup (defined in MAIN.C) is invoked to do the initialization of the scene. Include setting time-out values in this procedure, calling the request initialization function for each module. Of course, we also care about creating variable environments.
Php_hash_environment according to the Variables_order in php.ini to initialize each predefined large variable sequentially, then for $_get:
___fckpd___4
In general, this logic, first through the treat_data to generate variable hash (PG (http_globals) [Track_vars_get]), if you open the Auto_register_globals, then the $_ The variables in the get array are added to the symbol table.
Treat_data is a member of the Sapi_module_struct:
___fckpd___5
Now go back and look at Treat_data (i.e. Php_default_treat_data):
___fckpd___6
In the above logic, the res is replicated to Query_string, and the SG (request_info) is a structure representing the current request information, where query_string is in Php_apache_request_ ctor by copying the args in the Apache REQEUST_REC structure.
For the example of this article, Res is now "Name=laruence&career[]=yahoo&career[]=baidu",
To continue in the Treat_data, the following logic is:
___fckpd___7
First, by php_strtok_r the res into a "Key=value" segment based on "&", then the Var and Val are copied as key and value respectively, noting that the Var and Val are php_url_ in this process. Decode.
Finally, add a member named Var value of Php_register_variable_safe to Array_ptr (http_globals) [Track_vars_get], or $_get, at this point.
In this step, our $_get array contains the following members:
___fckpd___8
To be continued (the destruction process of the variable) ...
get[' name '];
We know that in the final execution period, the $_get array must contain the following fragment:
___fckpd___3
So, let's focus today on how Query string is built into _get arrays (for the generation of Get variables, please read my previous article: "PHP's Get/post and other large variable generation process"):
At the time of the request, the Php_request_startup (defined in MAIN.C) is invoked to do the initialization of the scene. Include setting time-out values in this procedure, calling the request initialization function for each module. Of course, we also care about creating variable environments.
Php_hash_environment according to the Variables_order in php.ini to initialize each predefined large variable sequentially, then for $_get:
___fckpd___4
In general, this logic, first through the treat_data to generate variable hash (PG (http_globals) [Track_vars_get]), if you open the Auto_register_globals, then the $_ The variables in the get array are added to the symbol table.
Treat_data is a member of the Sapi_module_struct:
___fckpd___5
Now go back and look at Treat_data (i.e. Php_default_treat_data):
___fckpd___6
In the above logic, the res is replicated to Query_string, and the SG (request_info) is a structure representing the current request information, where query_string is in Php_apache_request_ ctor by copying the args in the Apache REQEUST_REC structure.
For the example of this article, Res is now "Name=laruence&career[]=yahoo&career[]=baidu",
To continue in the Treat_data, the following logic is:
___fckpd___7
First, by php_strtok_r the res into a "Key=value" segment based on "&", then the Var and Val are copied as key and value respectively, noting that the Var and Val are php_url_ in this process. Decode.
Finally, add a member named Var value of Php_register_variable_safe to Array_ptr (http_globals) [Track_vars_get], or $_get, at this point.
In this step, our $_get array contains the following members:
___fckpd___8
To be continued (the destruction process of the variable) ...