Help with cron jobs

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Klown
Posts: 89
Joined: Tue Feb 22, 2011 5:59 am

Help with cron jobs

Post by Klown »

Hey guys,

I am wondering if any of you have faced this situation before.

I have multiple cron files setup to run at a specific time. Lets say each day at midnight. It's important that they all run within the same minute not 1 minute after the hour or 1 minute before the hour.

Lets say I have 1 cron file update all the players stats for the previous day such as number of employees. Next I would want a separate cron file run to update the records/high scores which would need to reference the data updated from the previous cron file.

Is there a way to force 1 cron file to run/complete before the next cron file within the same 1 minute time frame?

Any suggestions are greatly appreciated.
if( $myGames != "Crap" ) {
  • please_donate( $money );
} else {
  • just_enjoy();
}
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Help with cron jobs

Post by hallsofvallhalla »

put your second cron into a function in another page and include the page and call that function at the end of the first cron.

If you really want to separate them then you could put a flag in the DB that marks when the file has started and when it finishes. Then check it on the second cron. You will then need to run the cron more often in case the first time it fails.
Klown
Posts: 89
Joined: Tue Feb 22, 2011 5:59 am

Re: Help with cron jobs

Post by Klown »

hallsofvallhalla wrote:put your second cron into a function in another page and include the page and call that function at the end of the first cron.

If you really want to separate them then you could put a flag in the DB that marks when the file has started and when it finishes. Then check it on the second cron. You will then need to run the cron more often in case the first time it fails.
Thanks for the help - This sounds like an excellent solution.

Do you know if crons have a max execution time - and if they do - would you recommend doing something like: set_time_limit(0) inside the cron file?
if( $myGames != "Crap" ) {
  • please_donate( $money );
} else {
  • just_enjoy();
}
Post Reply

Return to “Beginner Help and Support”