Пример #1
0
 /**
  * SocketPingWrapper::Ping()
  * 
  * @return boolean true when ping is executed false when ping failed to execute.
  */
 function Ping($try = array('http', 'ftp', 'telnet', 'mail'))
 {
     if (empty($try)) {
         $try = array('http', 'ftp', 'telnet', 'mail');
     } else {
         if (!is_array($try)) {
             $try = array($try);
         }
     }
     if (empty($this->mInput)) {
         if (false !== $this->mDebug) {
             echo "Error: no ping target specified.";
         }
         return false;
     }
     if (!is_array($this->mInput)) {
         $this->mInput = array($this->mInput);
     }
     foreach ($this->mInput as $key => $host) {
         $this->mInfo = array();
         $up = false;
         foreach ($try as $service) {
             $tping = new TcpPing($host, $service);
             if ($result = $tping->Ping()) {
                 $up = true;
                 $this->mInfo[] = "service={$service} time=" . $tping->GetTime();
                 break;
             } else {
                 /**
                  * If current error message is different from the last one, take it.
                  */
                 if (!sizeof($this->mInfo) || $tping->GetErrorMessage() != $this->mInfo[sizeof($this->mInfo) - 1]) {
                     $this->mInfo[] = $tping->GetErrorMessage();
                 }
             }
         }
         $this->mOutput[] = "{$host} [" . $tping->GetTargetAddress() . "] is  " . ($up ? 'Alive.' : 'Down!!') . ' ' . implode(" ", $this->mInfo);
     }
     return true;
 }