3

I'd like to run cron every 5 minutes, but the UI doesn't offer any increment of time smaller than an hour. I'm assuming the solution is as simple as

  • creating a feature module for the setting, and changing the integer to 300 (60 seconds × 5), OR
  • cracking open the database and changing the value to 300.

Are there any hidden 'gotchas' with either of those approaches (or any reason they'll fail)? Is there a better way?

3 Answers 3

10

You can get really fine-grained control over your cron runs with these modules:

  • Elyisa cron

    Elysia Cron extends Drupal standard cron, allowing a fine grain control over each task and several ways to add custom cron jobs to your site.

  • Ultimate Cron

    The Ultimate Cron handling for Drupal. Runs cron jobs individually in parallel using configurable rules, pool management and load balancing.

(In no particular order) I've only used Elysia cron before, and only recently at that, but it works well.

Either module will let you use a standard cron rule to define it's frequency, which I think means you can get the granularity down as far as seconds if you need it.

I think the only gotcha is that the more often you run cron (if it has expensive tasks to perform), the more load there will be on your server. Testing and benchmarking are the only real way to solve that one :)

0
5

You can also just run a cron job from the server. If Cpanel is in use, it's simple to run cron.php on any schedule.

5
  • 1
    Heh, oh yeah...Drupal has consumed me, I can't conceive of a non-module based solution to anything any more :P
    – Clive
    Commented Oct 4, 2012 at 18:04
  • Is there any advantage to this? I'd be happy to use a real crontab (not from Cpanel but from the Unix command line) if there's some hidden problem with Drupal's built-in "cron", or some advantage (reliability?) of using a real crontab. However, it's much nicer to keep things together, and not have an external dependency that must be managed separately from everything else, so a real crontab definitely has a strong disadvantage in that respect.
    – iconoclast
    Commented Oct 4, 2012 at 18:42
  • 2
    AFAIK, Drupal's built-in cron runs on page load which makes for a slower user experience.
    – keva
    Commented Oct 5, 2012 at 21:03
  • The last comment isn't exactly true. The built in cron does run on request, but not page load. Instead it runs on a shutdown hook after the output buffer has been sent. This ends with no noticeable slower user experience as the connection to the browser has already been closed. See api.drupal.org/api/drupal/includes%21common.inc/function/… Commented May 1, 2023 at 2:15
  • In reference to the advantages to using crontab or some other job scheduling service such as cpanel... the crontab or scheduling service has the advantage of being predictable. As opposed to relying on the whims and bouts of traffic hitting the site, a crontab will happen at the moment you schedule it for. Additionally you have the flexibility of choosing the intervals, be it every hour, 3, or less... but also you can potentially make drupal cron run more frequently during business hours versus over night. Commented May 1, 2023 at 2:20
0

I have another option, if you are ok using the stock "automated cron" (aka poor man's cron) module that comes with drupal, which I'm assuming based on the question, you are.

You can set the interval for cron using settings.php.

In drupal 7

$conf['cron_safe_threshold'] = 300;

In drupal 8+

$config['automated_cron.settings']['interval'] = 300;

Obviously, do to the nature of the way the Drupal automated cron works, this wouldn't garentee the cron to be run every 5 minutes, but instead would be run on the next visit to any page that hit Drupal after 5 minutes have pasted since the last run. This is also true with the standard settings but at larger intervals obviously. This does mean if you do have edge caching like varnish in front or simply little traffic to the site, this may not be ideal.

Also, given the setting is set via settings.php, the drop down will no longer show the correct value and may be misleading to another developer or administrator.

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.