Stumbled upon this clean php function:
<?php
// Function to check response time
function pingDomain($domain){
$starttime = microtime(true);
$file = fsockopen ($domain, 80, $errno, $errstr, 10);
$stoptime = microtime(true);
$status = 0;
if (!$file) $status = -1; // Site is down
else {
fclose($file);
$status = ($stoptime - $starttime) * 1000;
$status = floor($status);
}
return $status;
}
?>
Works like a charm, maybe you should tweak the timeout a little bit if it feels too long.
As an extra it returns the response time which is pretty cool for statistics.
Read more about it here.