PHP source code analysis-session. auto_start configuration analysis
Author: zhanhailiang date:
Application Analysis
In daily development, if session. auto_start = 0 is configured in php. ini by default, session_start must be called to enable the session:
Kernel analysis
By checking the source code, we can see that session_start is defined as follows:
1881/* {proto bool session_start (void) 1882 Begin session-reinitializes freezed variables, registers browsers etc */1883 static PHP_FUNCTION (session_start) 1884 {1885/* skipping check for non-zero args for performance reasons here? */1886 php_session_start (TSRMLS_C); 1887 1888 if (PS (session_status )! = Php_session_active) {1889 RETURN_FALSE; 1890} 1891 RETURN_TRUE; 1892}
The essence of session_start is to enable the session by calling php_session_start.
If session. auto_start = 1 in php. ini is enabled by default, php_session_start is automatically called in RINIT (Request Initialization) by the source code to enable the session:
2129 static PHP_RINIT_FUNCTION (session)/* {*/2130 {2131 php_rinit_session_globals (TSRMLS_C); 2132 2133 + ----- 8 lines: if (PS (mod) = NULL) {queue-2141 2142 + ----- 8 lines: if (PS (serializer) = NULL) {queue 2150 2151 + ----- 5 lines: if (PS (mod) = NULL | PS (serializer) = NULL) {limit 2156 2157 if (PS (auto_start) {2158 php_session_start (TSRMLS_C); 2159} 2160 2161 return SUCCESS; 2162} 2163 /*}}}*/