title: PHP checking if server is alive
body: <p>I need to check if a group of servers, routers and switches is alive. I have been searching for something reliable that would work with IPs and ports for over an hour now, could anyone help?</p>
  
  <p>Ended up using</p>
  
  <pre><code>function ping($addr, $port='') {
      if(empty($port)) {
          ob_start();
          system('ping -c1 -w1 '.$addr, $return);
          ob_end_clean();
          if($return == 0) {
              return true;
          } else {
              return false;
          }
      } else {
          $fp = fsockopen("udp://{$addr}", $port, $errno, $errstr);
          if (!$fp) {
              return false;
          } else {
              return true;
          }
      }
  }
  </code></pre>