This is my PHP CURL function for pinging hosts:
function ping_url($host)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
$httpResponse = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if(!$httpResponse or empty($httpResponse)) {
return false;
}
return true;
}
It works for the majority of domains. However, today I tried the following:
if (!ping_url('zapper.com')) {
echo 'false';
} else {
echo 'true';
}
and it keeps failing.
Any ideas why this could be happening? The website zapper.com exists.
Thank you!
Try to add this option:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Hope it can help you.