i-CONICA
asked on
How to repeat this script, using POST data every 30 seconds or so...?
Hi,
I've got this script attached, which checks if a server is responding or not, like "ping example.com"...
I want to modify this script so that every 30 seconds, it'll repeat, to continually recheck the domain.
I thought about using sleep(), but that'd time the script out eventually, and I think using a meta refresh or javascript refresh wouldn't resubmit the post data...
Any thoughts?
Thanks.
I've got this script attached, which checks if a server is responding or not, like "ping example.com"...
I want to modify this script so that every 30 seconds, it'll repeat, to continually recheck the domain.
I thought about using sleep(), but that'd time the script out eventually, and I think using a meta refresh or javascript refresh wouldn't resubmit the post data...
Any thoughts?
Thanks.
<?php
// Function to check response time
function pingDomain($domain)
{
$starttime = microtime(true);
$file = @fsockopen($domain, 80, $errno, $errstr, 10);
$stoptime = microtime(true);
$status = 0;
if (!$file)
$status = -1; // Site is down
else {
fclose($file);
$status = ($stoptime - $starttime) * 1000;
$status = floor($status);
}
return $status;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="domain">
Domain name:
<table>
<tr><td><input name="domainname" type="text" /></td></tr>
<tr><td><input type="submit" name="submitBtn" value="Ping domain"/></td></tr>
</table>
</form>
<?php
// Check whether the for was submitted
if (isset($_POST['submitBtn'])) {
$domainbase = (isset($_POST['domainname'])) ? $_POST['domainname'] : '';
$domainbase = str_replace("http://", "", strtolower($domainbase));
echo '<table>';
$status = pingDomain($domainbase);
if ($status != -1)
echo "<tr><td style='padding:10px;background:#cfc;border:1px solid #3c3;'>http://$domainbase is UP ($status ms)</td><tr>";
else
echo "<tr><td style='padding:10px;background:#fcc;border:1px solid #c33;'>http://$domainbase is DOWN</td><tr>";
echo '</table>';
}
?>
</body>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys. I agree the AJAX way would be better, but the simple JS will do for this. Thanks.
ASKER
If you think that's the only way, it seems a bit convoluted, so might just keep hitting F5...