How often does hook_cron happen? what is the periodic time for executing the codes inside this hook?
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.
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".