Monday, February 9, 2015

Does file_get_contents() have a timeout setting?

The default timeout is defined by default_socket_timeout ini-setting, which is 60 seconds. You can also change it on the fly:

ini_set('default_socket_timeout', 900); // 900 Seconds = 15 Minutes

Another way, to set a timeout, would be to use stream_context_create to set the timeout as HTTP context options of the HTTP stream wrapper in use:

$ctx = stream_context_create(array('http'=>
    array(
        'timeout' => 1200, // 1 200 Seconds = 20 Minutes
    )
));

echo file_get_contents('http://example.com/', false, $ctx);

Reference:

http://stackoverflow.com/questions/10236166/does-file-get-contents-have-a-timeout-setting

No comments: