I have this code for checking urls:
function check_url($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch , CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$headers = curl_getinfo($ch);
curl_close($ch);
return $headers['http_code'];
}
And my arrays:
$urls = array(1,2,3,"AAAA",4,5,6,7,8,9);
(For example AAAA takes 200ms and others takes 4s)
And this is my loop
foreach ($urls as $url) {
check_url("http://www.example.com/" . $url);
}
Question is how can I set a timeout for each member? I mean, If checking member takes more than 2ms, jump to next member.