Cron Timing
Steven Barre
steven at realestatewebmasters.com
Wed Apr 21 16:41:09 UTC 2010
Thanks Cameron
I ended up just adding a random sleep to the crons
<?php
sleep(rand(0,600));
?>
But I do like that idea of a wrapper script or a lock script.
=================================================
Steven Barre
steven at realestatewebmasters.com
Systems and Support Manager
Real Estate Webmasters
www.realestatewebmasters.com
==================================================
On 4/20/2010 18:34, Cameron Simpson wrote:
> On 20Apr2010 09:34, Steven Barre<steven at realestatewebmasters.com> wrote:
> | I know that you can get cron to do something "every x". For example
> | to have something run every 15 min you would do
> |
> | */15 * * * * php /path/to/script.php
> |
> | But now I have a whole bunch of these set up and having them all run
> | at exactly the same time is causing issues.
> |
> | Is there any way to stagger these? Like tell it to run every 15 min
> | + 2 min so it runs at 02, 17, 32, and 47 minutes past the hour?
> |
> | Or is my best bet to simply put a sleep at the start of the script
> | with a random time?
>
> Leaving aside the other suggestions to simply write staggered times,
> some other "automatic" approaches are available.
>
> 1: Put all the jobs in one shell script:
>
> #!/bin/sh
> php /path/to/script1.php
> php /path/to/script2.php
> ... etc ...
>
> and have in cron:
>
> */15 * * * * /path/to/the-above-wrapper-script
>
> which will run them in sequence.
> Of course that relies on the all having exactly the same timing.
>
> 2: Use a locking system:
>
> */15 * * * * with_lock "lock_name" php /path/to/script1.php
> */15 * * * * with_lock "lock_name" php /path/to/script2.php
>
> which prevents any of them running at the same time. with_lock is a
> script you must write, to obtain a lock of some kind, run the command, and
> release the lock. That way when two jobs coincide, one will wait for the
> other to complete before proceeding.
>
> I use this script:
> http://www.cskk.ezoshosting.com/cs//css/bin/lock
> for this purpose.
>
>
>
More information about the redhat-list
mailing list