What to do if your cron job is failingPosted: December 7, 2005
If you’re finding that your cron job is failing often, its most likely one of the two problems:
- Your server was down when WebBasedCron tried running your file OR
- Your script took longer than the max execution time allowed. (most likely)
When a cron job is created, its given a maximum of 30 seconds execution time. You can open a support ticket, and we can increase your max execution time.
Some of our customers have cron jobs which take a long time to execute. For example, a blog related script could take up to 5 minutes (or more) to finish. WebBasedCron offers cron job execution by the minute, so allowing a cron job to take 5 minutes to run is dangerous.
I’m going to explain a solution below, were your cron job can take as long as you want, and WebBasedCron will never stop it. The solution below uses PHP coding, but a similair type of solution can be created with any server side language (i.e. ASP, etc.)
Lets say the script you want to run is http://www.yourdomain.com/post.php
Normally, you would go to WebBasedCron and set a cron job to run the URL above.
Now, instead of running that URL directly, we’re going to make a new file call it wbc.php – so the URL for this file would be http://www.yourdomain.com/wbc.php.
Inside wbc.php you would have the following:
$command = “php -d max_execution_time=’10000′ -f post.php >/dev/null &”;
Basically, the wbc.php script, when called by WebBasedCron, will run post.php in the background on your server. This way, WebBasedCron will run wbc.php and leave your server. But in actual fact post.php will have been running in the background on your server, and will continue to execute till it finishes.
means that post.php will be executed for a maximum of 10,000 seconds (change this as you like). The part which makes post.php run in the background is the ‘&’ in command.
To download the file click here. Just remove the .txt.
If you have any questions, please post a comment or open a support ticket.