Does file_get_contents() Have a Timeout Mechanism?
When processing multiple links in a loop using file_get_contents(), it's crucial to understand if PHP's implementation has a timeout feature to prevent a premature move to the next link.
Timeout Period:
Yes, file_get_contents() has a timeout period determined by the default_socket_timeout ini-setting. By default, this value is set to 60 seconds.
Adjustable Timeout:
To modify the default timeout setting, you can use the following methods:
ini_set('default_socket_timeout', 900); // 900 Seconds = 15 Minutes
$ctx = stream_context_create(array('http' => array( 'timeout' => 1200, //1200 Seconds is 20 Minutes ) )); echo file_get_contents('http://example.com/', false, $ctx);
By setting a longer timeout period, you can ensure that each link is processed fully before moving on to the next one.
The above is the detailed content of Does `file_get_contents()` Have a Timeout Mechanism to Prevent Premature Link Skipping?. For more information, please follow other related articles on the PHP Chinese website!