views:

47

answers:

3

Hello, i try to make a script to check if my server are online or offline:

<?

    $server = "12.34.56.78";

    $check = @fsockopen($server, 22);

    if ($check) {
        @fclose($check);
        echo "online";
        exit;
    }else{
        echo "offline";
    }

?>

so this script works, but how can i make the script that i can check more than one ip address?

Greetings, matthias

+2  A: 
function checkServerOnline($server, $port = 22) {
    $check = @fsockopen($server, $port);
    if ($check) {
        @fclose($check);
        return true;
    } else {
        return false;
    }

Then you can call it with various server-port-combinations.

alopix
thanks this is a good answer too
matthias
A: 

There is open source tools for this readily available.

Check out Nagios - The Industry Standard In Open Source Monitoring:

Nagios is a powerful monitoring system that enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes.

Nagios monitors your entire IT infrastructure to ensure systems, applications, services, and business processes are functioning properly. In the event of a failure, Nagios can alert technical staff of the problem, allowing them to begin remediation processes before outages affect business processes, end-users, or customers. With Nagios you'll never be left having to explain why a unseen infrastructure outage hurt your organization's bottom line.

Gordon
thanks, but i think this is a little bit to mutch :-)
matthias
+2  A: 
$servers = Array("server1", "server2");

foreach ($servers as $server) {
  // same as before
}
Amadan