why do curl response code zero (sometimes)?

Viewed 12

I have some pool of links. I need to get one of links, check is it response good and redirect user then. Most time everything are ok.

Problem is some links may response with code zero from time to time, its not always respond with zero. Zero response code means (as far as I understand) curl cant get any response from server. But i know, in fact link works pretty good. And next try i will get 200.

I've tried to set more attempts with sleep() between them if httpcode are zero, but it seems to curl dont care about that and continues to respond with zero.

Any chance i can get response code more stable?

$curl = curl_init($link);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl,CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_exec($curl);
$response = curl_getinfo($curl);

if ($response['http_code'] < 200 || $response['http_code'] >= 300) {
  $this->sendAlert($link, $response);
  return false;
}

return true;
0 Answers
Related