예제 #1
0
 /**
  * Ping a address
  * @return int if -1 the server is down
  * @access public
  */
 static function ping($address)
 {
     $urlInfo = parse_url($address);
     $domain = $urlInfo['host'];
     $port = Net::getUrlPort($urlInfo);
     $starttime = microtime(true);
     $file = @fsockopen($domain, $port, $errno, $errstr, 10);
     $stoptime = microtime(true);
     $status = 0;
     if (!$file) {
         $status = -1;
     } else {
         fclose($file);
         $status = ($stoptime - $starttime) * 1000;
         $status = floor($status);
     }
     return $status;
 }