PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.php > working as a daemon and execute tasks at a certain time
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
working as a daemon and execute tasks at a certain time

Réponse
 
LinkBack Outils de la discussion
Vieux 10/10/2007, 12h11   #1
Dirk Laurenz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut working as a daemon and execute tasks at a certain time

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

Greetings, Dirk

  Réponse avec citation
Vieux 10/10/2007, 12h23   #2
BoneIdol
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: working as a daemon and execute tasks at a certain time

You could always make it run the task every 86400 seconds...

Anyway your code executes twice because you use 2 equal than or
greater/less than. Remove an = from that if and it should work ok.

I think anyway.

  Réponse avec citation
Vieux 10/10/2007, 12h29   #3
Dirk Laurenz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: working as a daemon and execute tasks at a certain time

Hi,

BoneIdol schrieb:
> You could always make it run the task every 86400 seconds...


this was my guess, but depends on starting the daemon at 1800 hours,
isn't it.

> Anyway your code executes twice because you use 2 equal than or
> greater/less than. Remove an = from that if and it should work ok.
>
> I think anyway.
>

that does not change anything case the function can execute more than
once per second and a sleep 1 can lead to miss the time. i already
tested this.

dirk
  Réponse avec citation
Vieux 10/10/2007, 12h34   #4
BoneIdol
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: working as a daemon and execute tasks at a certain time

Couldn't you do a bit of a dirty hack and make a variable to say that
the code has run today and not to execute this code again until
tommorow?

I'm not overly familiar with daemons in php, by the way.

  Réponse avec citation
Vieux 10/10/2007, 14h58   #5
FD
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: working as a daemon and execute tasks at a certain time

"Dirk Laurenz" <dirk.laurenz@fujitsu-siemens.com> schreef in bericht
news:feic0q$qc2$1@nntp.fujitsu-siemens.com...
> 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 ....
>
> Greetings, Dirk



1800 hours happens only once a day, so you must keep track of the last day
that the task is done.

$done_day = 0;
while (true)
{
if ($done_day <> today() && $current_time >= 1800)
{
$done_day = today();
dosomething...
}
}

today() should return the current day of the week, month or year.

Frank


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 06h11.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09049 seconds with 13 queries