PHP checking if server is alive
<p>I need to check if group of servers, routers and switches is alive, have been searching for something reliable that would work with IPs and ports for over an hour now, anyone could 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>
