I have picked up a PHP ping tool and with help from another member here I have managed to get it to display everything I need correctly. The problem I'm having is this has to ping 115 different IP Addresses and some times gets the "Fatal Error maximum execution time of 30 seconds"
I have copied the code below and have only added 1 host and 1 service as to save space but there is normally 115 hosts and 115 services.
$host1[1] = "8.8.8.8";//These addresses are generic for security reasons.
$host1[2] = "8.8.8.8";
$host1[3] = "8.8.8.8";
$services1[1] = "site 1";//These site names are generic for security reasons.
$services1[2] = "site 2";
$services1[3] = "site 3";
$counter = "";
$has_down = false; // flag, no sites are down yet
foreach ($host1 as $value1)
{
$counter = $counter + 1;
echo "<tr>";
echo '<body bgcolor="#FFFFFF" text="#000000"></body>';
//check target IP or domain
$pingreply = exec("ping -n $count $value1");
if ( substr($pingreply, -2) == 'ms')
{
}
else
{
echo "<p><font size='6'><center><strong><div class='alert alert-danger'>" . $services1[$counter] . " - No Reply</div></strong></center></font></p>";
// site down, set flag
$has_down = true;
}
}
// flag still false, all sites work
if (!$has_down) {
echo "<p><font size='6'><center><strong><div class='alert alert-success'>All sites responding to pings</div></strong></center></font></p>";
}
Where there is $host1 and $services1 I have 115 of these but I have only put 3 on the code here so it doesn't take up loads of space on the question.
Is there any way I can improve this as it is taking a long time to load the page and it is sometimes getting a fatal error if it takes to long.
Also I believe it is only sending 1 ping per $host but i'm wondering if I can get this to send 4 ping packets to site and if it gets an average ping response then the site is up, as we have some sites on ADSL Lines which often drop packets when pinging so when the site refreshes it says they are down but they have only dropped 1 ping.
Can we optimise this and increase the amount of pings to site?
Thanks for your help in advanced.