Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
/lib/ -> cronlib.php (source)

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]

Cron functions.

Copyright: 1999 onwards Martin Dougiamas http://dougiamas.com
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 443 lines (15 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 8 functions


Functions that are not part of a class:

cron_run()   X-Ref
Execute cron tasks


cron_run_scheduled_tasks(int $timenow)   X-Ref
Execute all queued scheduled tasks, applying necessary concurrency limits and time limits.

param: int     $timenow The time this process started.

cron_run_adhoc_tasks(int $timenow, $keepalive = 0, $checklimits = true)   X-Ref
Execute all queued adhoc tasks, applying necessary concurrency limits and time limits.

param: int     $timenow The time this process started.
param: int     $keepalive Keep this function alive for N seconds and poll for new adhoc tasks.
param: bool    $checklimits Should we check limits?

cron_run_inner_scheduled_task(\core\task\task_base $task)   X-Ref
Shared code that handles running of a single scheduled task within the cron.

Not intended for calling directly outside of this library!

param: \core\task\task_base $task

cron_run_inner_adhoc_task(\core\task\adhoc_task $task)   X-Ref
Shared code that handles running of a single adhoc task within the cron.

param: \core\task\adhoc_task $task

cron_set_process_title(string $title)   X-Ref
Sets the process title

This makes it very easy for a sysadmin to immediately see what task
a cron process is running at any given moment.

param: string $title process status title

cron_trace_time_and_memory()   X-Ref
Output some standard information during cron runs. Specifically current time
and memory usage. This method also does gc_collect_cycles() (before displaying
memory usage) to try to help PHP manage memory better.


cron_prepare_core_renderer($restore = false)   X-Ref
Prepare the output renderer for the cron run.

This involves creating a new $PAGE, and $OUTPUT fresh for each task and prevents any one task from influencing
any other.

param: bool    $restore Whether to restore the original PAGE and OUTPUT