Created
October 16, 2013 02:41
-
-
Save eddy8/7001838 to your computer and use it in GitHub Desktop.
php ping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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