Check serverlist offline / online PHP

折月煮酒 提交于 2019-12-11 05:29:31

问题


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


回答1:


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

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



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/3404885/check-serverlist-offline-online-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!