Recently in the study of some POC, found that most of the POC will have such a ini_set (' Default_socket_timeout ', 5), meaning that the configuration Default_socket_timeout set the parameters of 5. Do not know what the meaning of this configuration, to the official online check, given the explanation is very simple default timeout (in seconds) for socket based streams. The timeout for the socket stream (the parameter is in seconds). I want to try this effect, but search for a long time, there is no domestic and foreign countries can reflect the significance of this parameter examples. So casually found a simple code to try the following, the code is as follows:
\<\?php $url = ' Http://www.cnblogs.com/Zjmainstay/archive/2012/03/08/PHP_FUN ction_file_get_contents.html '; Ini_set (' Default_socket_timeout ', 3); if ($data = file_get_contents ($url)) {echo $data;} else {echo ' Timeout ';} \?\>
The meaning is very simple, is to get a page, the socket stream time set to 3 seconds, the effect is as follows
Later I will change the default_socket_timeout time to 0.1 seconds, that is, Ini_set (' Default_socket_timeout ', 0.1), and then access, the effect is as follows
In writing this article, suddenly found that the original PHP official web site on this set of sample code, and I compare the experiment to see it.
through search explanations and experimental tests, I get the conclusion that the Default_socket_timeout is the timeout parameter for the socket stream, That is, the socket stream from the establishment to the transfer to the closure of the entire process must be within the time set by this parameter, if not complete, then PHP will automatically end the socket and return a warning. A similar PHP configuration is connection_timeout, but connection_timeout means that the time to keep the connection timed out does not include creating and destroying connections.