ping function

/*
   parameter host,port,timeout(sec)
   return type array result
*/

function ping($host, $port, $timeout) {
  $tB = microtime(true);
  try{
       
      $fP = fSockOpen($host, $port, $errno, $errstr, $timeout);
      if (!$fP) {
          $tA = microtime(true);
           $data = array(
                "ms" => round((($tA - $tB) * 1000), 0)." ms",
                "status" => "FAIL",
                "message" => "sitedown"
           );
        return $data;
      }
      $tA = microtime(true);
      $data = array(
                "ms" => round((($tA - $tB) * 1000), 0)." ms",
                "status" => "OK",
                "message" => ""
      );
      return $data;
  }
  catch(Exception $e)
  {
      $tA = microtime(true);
     $data = array(
                "ms" => round((($tA - $tB) * 1000), 0)." ms",
                "status" => "FAIL",
                "message" => $e->getMessage()
      );
      return $data;
  }
}

Related posts:

This entry was posted in php. Bookmark the permalink.