Using PHP's Curl how do I know that the page is not responding so as to grab another one?
+2
A:
Use the CURLOPT_CONNECTTIMEOUT
option:
// Wait two seconds before bailing
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
There's also CURLOPT_TIMEOUT
, which works for an entire request call (including DNS fetching and reading the data).
To check if a call did time out, you may be able to check its return value. If not, the CURL handler's curl_errno
is set, which you can compare to CURLE_OPERATION_TIMEDOUT
(or just CURLE_OK
).
strager
2010-08-20 12:13:57
But this is not his question, is it? The question is how to tell a call timed out (as opposed to some other error)
Pekka
2010-08-20 12:17:49
@Pekka, Oh, seems I misread the question. I'll update my answer.
strager
2010-08-20 12:26:48