0

Using PHP's Curl how do I know that the page is not responding so as to grab another one?

2
  • Set timeout as strager responded, check return code of curl_exec, and you can also retreive some usefull information by curl_getinfo() Commented Aug 20, 2010 at 12:30
  • When the result array had it's errno key set to 28. Just like this: ["errno"]=>int(28) Commented Jul 4, 2011 at 5:32

1 Answer 1

3

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).

Sign up to request clarification or add additional context in comments.

2 Comments

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, Oh, seems I misread the question. I'll update my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.