1

How often does hook_cron happen? what is the periodic time for executing the codes inside this hook?

8

As often as you like :)

  • By default you can configure it on: /admin/config/system/cron (This will be executed on someone's page load, so it is importan to know that if nobody visits your site this will not be executed). This is known as poormanscron (Drupal 6).
  • Calling with a internal/external cron script (wget for example) to yoursite.com/cron.php

This is a heavy process so normally you want to limit cron functions like check updates. elysia cron is very useful in this case.

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.

  • Just in case you meant 'internal' in the truest sense - there's nothing stopping you from invoking the cron from an external server, it doesn't need to be internal. Plus even the internal request would need to have the cron key appended – Clive Apr 7 '14 at 15:13
  • 1
    yes, of course, edited! – jorgetutor Apr 7 '14 at 15:14
2

It's either:

  1. What you set it as at /admin/config/system/cron or
  2. How often you invoke the cron script externally.

It's totally under your control.

1

hook_cron() is triggered whenever Drupal's cron function runs.

The default is to trigger every 3 hours. However you decide when Drupal's cron function runs.

On a typical Drupal 7 site, you control this by navigating to Administration » Configuration » System » Cron to set the frequency. This default method of running cron is sometimes known as "Poormanscron". Poormanscron is executed upon page load, which means it may fail to trigger if your site receives very little traffic.

You may, as an alternative, use an external trigger for cron. The URL (inclusive secret key) for using an external trigger for Drupal's cron function is given on the same page, after the text: "To run cron from outside the site, go to ...". When doeing this, you may disable Poormanscron by setting the frequency to "Never".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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