I am pinging an array of 12 machines by ip address
and displaying the status (host is alive or not) on a simple web interface.
This is the code that I currently have -
$hosts = array ("192.168.0.100","192.168.0.101","192.168.0.102"); //etc..
foreach ($hosts as $hosts) {
exec ("ping -i 1 -n 2 -l 1 $hosts", $ping_output);
if(preg_match("/Reply/", $ping_output[2])) {
echo "$hosts replied! <br />";
} else {
echo "$hosts did not reply! <br />";
}
}
This works, but does not scale very well. I have to wait about 15 seconds before the page loads because it's pinging all machines and takes time. I reduce the ping count to only 2 replies, lowered the buffer size as well.
Is there a better approach to this? More efficient? Better than 15 seconds? Any suggestions are appreciated.
Thanks