Moodle's cron.php
is an administrative process that is run on a scheduled basis to perform maintenance tasks such as e-mail delivery and backups. It is typically run once in every 5 to 15 minutes on most sites. Occasionally, while working with blocks or other plugins, it will be necessary to add some of your own processing to cron.php
. This is a convenient way of making sure that your module can run background processes without giving the end user a series of complex instructions for a separate cron entry.
To add cron support to our block we just have to set the cron interval in the init()
function with the following line of code, and define a cron()
function in our block class:
$this->cron = 5;
The value assigned to $this->cron
is the number of seconds between cron runs. It is important to note that no matter what this is set to, the module cron code will only run as frequently as the main site is set to run.
To complete our functionality, we...