Zhanhailiang Date: 2014-10-20
Application analysis
In daily development, the php.ini configuration session.auto_start=0 closes the session by default if you want to open the session to call Session_Start:
<?php Session_Start (); //...
Kernel analysis
By checking the source code, we know 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) {1889Return_false;1890 }1891return_true;1892 }
You can see that the Session_Start essence is to open the session by calling Php_session_start.
If you modify the php.ini in Session.auto_start=1 by default when the session is opened by the source, the Rinit (that is, request initialization) automatically calls Php_session_start to open the conversation:
2129 Staticphp_rinit_function(Session) /* {{{ */2130 {2131php_rinit_session_globals(Tsrmls_c);2132 2133 +----- 8Lines: if (PS(MoD) ==NULL) {----------------------------------------------------------------------------------------------------------- ---------------------2141 2142 +----- 8Lines: if (PS(Serializer) ==NULL) {---------------------------------------------------------------------------------------------------------- ---------------2150 2151 +----- 5Lines: if (PS(MoD) ==NULL||PS(Serializer) ==NULL) {------------------------------------------------------------------------------------------------------2156 2157 if (PS(Auto_start)) {2158 Php_session_start(Tsrmls_c);2159 }2160 2161 returnSUCCESS;2162 }2163 /* }}} */
Session.auto_start Configuration Analysis of PHP source code analysis