Perl rookie wrote:
How can I run a script based on timer / counter ? What I am trying to
do is, every 5 minutes, I want a php script to execute that searches
my database and popup a small window if the search conditions are
met. I am pretty new to php programming.
It would be great, if anybody can help me with this.
Thanks
As is said by others, use cron on Linux, or 'at' in win32 in combination
with the commandline interface or create a script like this and run that in
a browser if you are serving from a host that does not offer cron jobs. Be
aware set_time_limit (0 is NOT allowed by all hosts, requires safe_mode off,
if safe_mode is enabled it will be ignored by PHP :
<?PHP
set_time_limit (0); // ensure the script keeps running and does not time
out.
$i = 0;
while (TRUE) {
$i++;
echo "Run $i times<br>";
ob_flush(); // use both ob_flush and flush to ensure
flush(); // output is written to the browser window
sleep(300); // 5 min interval
}
?>
I don't know if the browser creates its own time-out after a given amount
time, if that's the case it will probably be the same issue for whichever
solution you pick. Perhaps you could also use JavaScript to initiate the
process from the client side.
HTH
Pjotr