Sleep function in PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vestal
    New Member
    • Oct 2007
    • 1

    #1

    Sleep function in PHP

    Hi all,
    I'm developing a remainder kind of thing in PHP. I've some events which will be fired after certain amount of time..E.g..if one event is fired at 7:00 am then next event should be fired on next day at same time, so this is going to be in infinite loop..

    while(true)
    {

    event ;

    sleep();

    }

    But it's not working,..can we use multiple sleep() in one program?
    Can anyone have worked on the same..??
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    Originally posted by Vestal
    Hi all,
    I'm developing a remainder kind of thing in PHP. I've some events which will be fired after certain amount of time..E.g..if one event is fired at 7:00 am then next event should be fired on next day at same time, so this is going to be in infinite loop..

    while(true)
    {

    event ;

    sleep();

    }

    But it's not working,..can we use multiple sleep() in one program?
    Can anyone have worked on the same..??
    Hi Vestel,

    for it to be an infinite loop it requires someone is executing the file (constantly viewing the php page).

    The sleep function takes and int as parameter, the int represents the number of seconds you want the program to sleep. In you case this will be 24h = 1440min = 86400s.

    Cheers

    Comment

    • adamalton
      New Member
      • Feb 2007
      • 93

      #3
      You might want to try learning about 'cronjobs'. It's where you can tell your webserver to do things on a set schedule. I don't know much about it but I think it's what you need. As was mentioned above, to get your script to work you would need to be accessing that page 24/7. Once you exit the page the script is terminated. Although there is a php function ignore_user_abo rt() or something like that which might allow the script to carry on forever even when you leave the page. But if you did that you'd have to restart your server when you wanted to stop it/change the script, which if your server is on a paid webhosting thing might be a bit tricky!!

      Comment

      Working...