HI Guys,
I'm VERY VERY new to constructing PHP although I've edited and 'hacked' quite a few pages in the past...
I need help with coding/syntax to the extreme on this one, so any and all suggestions would be GREATLY appreciated.
I'm creating a page that will be used to monitor our server status. I'm using the following code to currently PING the device and then read in the results and it works, but i need to alter it. I'm going to put this page on our INTRANET and if all 350 users connect to the page, then theoretically it'd run 350 pings, which i DON"T need.
I want to make the page ONLY run if it HASN'T yet run in the last five minutes. So my logic would be to:
a) store a variable somewhere (on the page itself) that holds the LAST RUN DATE/TIME.
b) get the current date/time
c) compare the current date/time versus the "last run" date time. If >5 min. has passed, run my code (shown below)... if not, show LAST results.
Will I need to use MySQL for this, or could I just have PHP write a TXT file or variable to do all this?
Like I said, I'm an EXTREME newbie and want something SUPER SIMPLE!
Thanks in advance for any/all suggestions.
Here's my code currently.
<?php
function ping($server) {
$ping = shell_exec('ping -c 2 -t 5 ' . $server . '');
#$reply = preg_match('/([0-2]) packets received/', $ping, $data);
$reply = preg_match('/([0-2]) received/', $ping, $data);
$packets = intval($data[1]);
if($packets>0)
{
$status = "{$server} <font color=\"green\">Online</font><br>";
}
elseif($packets==0)
{
$status = "{$server} <font color=\"red\">Offline</font><br>";
}
else
{
$status = "{$server} <font color=\"black\">Unknown</font><br>";
}
return $status;
}
// Test ping: COMPerfection.com
#ping('www.google.com');
echo ping('www.website1.com');
echo ping('www.website2.com');
?>