$url = 'http://a.url/i-know-is-down';
//ini_set('default_socket_timeout', 5);
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 5,
'ignore_errors' => true
)
)
);
$start = microtime(true);
$content = @file_get_contents($url, false, $ctx);
$end = microtime(true);
echo $end - $start, "\n";
the response I get is generally 21.232 segs, shouldn't be about five seconds???
Uncommenting the ini_set line don't help at all.
ingnore_errors
because I need to distinguish between say a 404 error and an error generated by connectivity problems. Let me rephrase it. If ingnore_errors` is off and the server return a 404 $content would be false and i need to know if $content if false because a 404 error or beacuse a connectivity error. The error showed when I suppress the @ operator is a generic one likefile_get_contents(filename): failed to open stream
– Evergreen$http_response_header
after callingfile_get_contents()
. It gets populated as an array of the HTTP Headers returned by the server. You can get all errors except server connection problems (server not found, timeout, connection refused, etc) – Meyerhof