8

Whats the maximum execution time of cron. is it possible to modify it if so any side effects.

4 Answers 4

10

The accepted answer above is INCORRECT. Cron's time limit in Drupal is hardcoded to 240 seconds. See the drupal_cron_run function in includes/common.inc, specifically these lines:

drupal_set_time_limit(240);

and

if (!lock_acquire('cron', 240.0)) {

(based on the source of Drupal 7.12)

So, there is no way to change this globally without hacking core. I have heard it suggested to call drupal_set_time_limit yourself inside of your hook_cron implementation, as doing so resets PHP's counter. However that won't help you when it's a third-party module implementing hook_cron.

1
  • As of Drupal 8.7, the number is still 240 seconds, but it is set in web/core/lib/Drupal/Core/Cron.php: Environment::setTimeLimit(240);
    – froboy
    Oct 24, 2019 at 18:44
3

Maximum execution time for Drupal's cron depends on your php.ini.

For example if you use wget -O - -q -t 1 http://www.example.com/cron.php as your cron command, apache's php.ini is used to determine the maximum execution time.

If you use php -f cron.php as your cron command, then php-cli's php.ini is used to determine the maximum execution time.

It is recommended to use php-cli for higher execution time, where you can set the maximum execution time from /etc/php5/cli/php.ini (if you use debian linux) and have no side effects on apache while cron runs.

1
  • 2
    +1, but a word of warning when invoking cron via cli: Make sure that none of your modules hook_cron() implementations relies on using variables provided by the web server, as they will obviously not available in that context (spent quite some time once to find that a module used $_SERVER['DOCUMENT_ROOT'] on cron invocations). Nov 14, 2010 at 11:21
2

I don't know if this is necessarily the case as I've just run the cron.php through my browser and I'm getting a max excution time error of 240 seconds while my max execution time in my php.ini is 1200 seconds. So somewhere besides my php.ini file Drupal is grabbing the max execution time.

That somewhere would be in the ./includes/common.inc or ./includes/locale.inc. Head into there and there are settings to adjust how long drupal will allow the cron to run for before giving up

0

This module can help you: Set Cron Time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.