tags:

views:

110

answers:

4

Hi,

I have 5-6 jobs to be done by cron, and i have separated php scripts for those jobs.

My question is, which one is better, putting all the jobs in one php script or keeping them in separated php files and entering them to crontab separately ?

thx

A: 

If they all have to run at the same time, then it may be better to write a wrapper script that invokes them all (or enclose them all in one file), and call the one script from cron.

This is especially true if there is an order dependency, such that one script must run before another. Separating these in cron is tricky at best.

If they have to run at different times, then obviously separate cron jobs are warranted.

Marcelo Cantos
+7  A: 

I'd recommend separate scripts. Primarily it will be much easier to debug/diagnose issues when you get a "failed" email from cron if you know which script was running at the time.

It also allows you to run the other jobs even if one fails more easily.

It also gives you flexibilty to change the timings of different jobs (e.g. suppose you suddenly need to run one every 15mins, but all the others are hourly).

Paolo
+1 - Additionally, seperating them means that a crash/error in one of your tasks will not prevent your other tasks from being processed.
Kazar
+1  A: 

I'd suggest you to keep all this jobs separately, as this provides you with more flexibility, for example, when setting time.

deklin
A: 

I have multiple cron tasks which each run multiple shell scripts which contain multiple php/etc. scripts.

Works very nicely.

zaf