SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    *********! *********!!! jackli's Avatar
    Join Date
    Sep 2005
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sleep or cron job

    sleep or cron job
    (heh. no pun intended!)

    For a script (or loop in the script) that should be executed every interval, is it better to use a cron job or php sleep()?

    Also, for a cron job, how do you set it up to execute at a random (or otherwise changing) interval?

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jackli View Post
    For a script (or loop in the script) that should be executed every interval, is it better to use a cron job or php sleep()?
    Cron job. With sleep() you have to worry about what happens if the script dies. It'll keep using up more and more memory over time and become more and more likely to crash or do something unexpected.

    Quote Originally Posted by jackli View Post
    Also, for a cron job, how do you set it up to execute at a random (or otherwise changing) interval?
    Have it run on the minimum possible interval. For example, if you never run more than every 1 minute, then make it run EVERY 1 minute.

    Put the logic of whether it needs to run on this particular minute in the script itself. It can simply exit if it has nothing to do.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •