Sebastian
Sebastian

Reputation: 514

Check serverlist offline / online PHP

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

Upvotes: 0

Views: 5794

Answers (3)

Gordon
Gordon

Reputation: 316959

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.

Upvotes: 1

Amadan
Amadan

Reputation: 198314

$servers = Array("server1", "server2");

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

Upvotes: 2

dst
dst

Reputation: 1788

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.

Upvotes: 2

Related Questions