working as a daemon and executing tasks at a certain time
am 10.10.2007 13:21:36 von Dirk Laurenz
Hello,
i've written a daemon in php and everthing works fine.
i'm able to execute tasks periodically. for example every 900 seconds.
now i want the daemon to do a task only once a day,
for example at 1800 hours. but i'm not sure how to do
this.
saying something like
while (true)
{
if ($current_time==1800) dosomething
}
fails if i miss 1800 exactly.
saying something like
while(true)
{
if ($current_time<=1801 && $current_time=>1800) dosomething
}
leads to running the function twice, or more depending on
the execution time of the function.
I'm using php 4.3 (more is not allowed at the moment)
Thanks for any help....
Greetings, Dirk
Re: working as a daemon and executing tasks at a certain time
am 10.10.2007 13:36:47 von Tyno Gendo
Dirk Laurenz wrote:
> Hello,
>
> i've written a daemon in php and everthing works fine.
> i'm able to execute tasks periodically. for example every 900 seconds.
>
> now i want the daemon to do a task only once a day,
> for example at 1800 hours. but i'm not sure how to do
> this.
> saying something like
>
> while (true)
> {
> if ($current_time==1800) dosomething
> }
>
> fails if i miss 1800 exactly.
> saying something like
>
> while(true)
> {
> if ($current_time<=1801 && $current_time=>1800) dosomething
> }
>
> leads to running the function twice, or more depending on
> the execution time of the function.
>
> I'm using php 4.3 (more is not allowed at the moment)
>
> Thanks for any help....
>
> Greetings, Dirk
just use variable say $lastRun to store when the event last ran and then
you can check against that, within you if set $lastRun to the
$current_time when it runs and never run if $lastRun $current_time
aren't >= to the 1800 gap ?