Sunday, April 25, 2010

How to prevent cron from being DISABLED

Hello all,

Sometimes you may see your cron failed more than 9 consecutive times, and were disabled. You can see why here.

To prevent your script from being disabled, follow these suggestions:

- Set cron jobs running at a big interval, e.g once a hour (hourly) or once a day (daily).
If you are on a shared hosting, it is recommended to set cron jobs once a hour or more, as your hosting provider is happy to ban any IP making a lot of HTTP requests :D

- Set cron jobs running at "leisure" minutes.
"Remember that when you schedule your job to run at midnight every night, there may be a couple hundred other people thinking the same thing. If the exact time is not critical, consider scheduling your job for 11:56 PM or 12:03 AM.

You'll find there are much fewer jobs scheduled at this time and your job will often run faster and smoother than when you are wrestling for that coveted midnight position. You may want to avoid using minutes that are multiples of five (i.e. 5, 10, 15, 20, 25)."

- Combine similar cron
If you have some cron running at a same interval, e.g every 30 minutes, you can combine them into one using some code.

I've made one in PHP: http://tny.cz/9842a2e8
+ Edit file, insert your cron URLs before "SETCRONJOB;", one URL per line.
+ Upload that file into your web root (i.e can be access at http://yourdomain.com/cron.php)
+ Set cron jobs with the URL http://yoursite.com/cron.php
+ Disable the old cron.

Hope it helps :)

Best regards,
Nguyen An Thuan.