Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
/lib/ -> cronlib.php (source)

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

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: 451 lines (16 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