Crontab with a minute delay

I started to look into a way to get a php script to execute on a timed event. I found that crontab is used for this purpose. I can have quite a bit of control over it to run ever minute, hour, day, etc. It doesn’t give fine control allowing me to run during specific seconds though. My commands in the queue may end up waiting for a minute before they are actually executed. When there is only a few commands in the queue, this is unacceptable. Why wait when you can do it now? I wonder if there is another approach to this to run every 15 seconds.
posted by Dedric Mauriac on Woodbridge using a blogHUD : [blogHUD permalink]

2 Responses to Crontab with a minute delay

  1. Hi Dedric, Not sure if this will do what you need, but, in crontab, you might try invoking the script four times at once a minute and stagger the instances using sleep. Something like this:

    * * * * * * /foo/bar/script.php
    * * * * * * sleep 15; /foo/bar/script.php
    * * * * * * sleep 30; /foo/bar/script.php
    * * * * * * sleep 45; /foo/bar/script.php

    Hope this helps.

  2. cool, I had no idea about sleep! I must get more of it. 😉

%d bloggers like this: