Skip to content

Instantly share code, notes, and snippets.

@eddy8
Created October 16, 2013 02:41
Show Gist options
  • Save eddy8/7001838 to your computer and use it in GitHub Desktop.
Save eddy8/7001838 to your computer and use it in GitHub Desktop.
php ping
<?php
/**
*@param $domain string IP address or URL
*/
function pingDomain($domain){
$data = parse_url($domain);
if (isset($data['host'])) {
$domain = $data['host'];
}else{
$domain = $data['path'];
}
$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;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment