timer in php script

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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.


Re: timer in php script

Quoted text here. Click to load it

You can put a "refresh" <META> tag in the header so that it re-submits
it after 5 minutes.


DeeDee, don't press that button!  DeeDee!  NO!  Dee...

Re: timer in php script

or a chron job
Quoted text here. Click to load it

Re: timer in php script

Perl rookie wrote:
Quoted text here. Click to load it

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 :

set_time_limit (0); // ensure the script keeps running and does not time
$i = 0;
while (TRUE) {
      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.


Re: timer in php script

Pjotr Wedersteers wrote:
Quoted text here. Click to load it

Add to this equation Apache/IIS have their own time-out values as well. So
this may not be a solid route in all cases...

Re: timer in php script

hmm..may be i missed to mention one thing.  I have web application,
once the user logins in, I want to spawn a php app that will run in the
background as along as the user logged in. This app needs to check the
database once every say  5mins and popup a small window when a certain
criteria is met.   The refresh method might work, but that means, I
need to pop a new window and have it always be open.


Re: timer in php script

newbie programmer wrote:
Quoted text here. Click to load it

Yes, you are missing the fact that PHP runs on the SERVER and can not
open windows on the client's machine. Something on the client side
needs to open the window.

Ken Robinson

Site Timeline