Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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.
/admin/cli/ -> cron.php (source)

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

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * CLI cron
  20   *
  21   * This script looks through all the module directories for cron.php files
  22   * and runs them.  These files can contain cleanup functions, email functions
  23   * or anything that needs to be run on a regular basis.
  24   *
  25   * @package    core
  26   * @subpackage cli
  27   * @copyright  2009 Petr Skoda (http://skodak.org)
  28   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   */
  30  
  31  define('CLI_SCRIPT', true);
  32  
  33  require(__DIR__.'/../../config.php');
  34  require_once($CFG->libdir.'/clilib.php');      // cli only functions
  35  require_once($CFG->libdir.'/cronlib.php');
  36  
  37  // now get cli options
  38  list($options, $unrecognized) = cli_get_params(
  39      array(
  40          'help' => false,
  41          'stop' => false,
  42      ),
  43      array(
  44          'h' => 'help',
  45          's' => 'stop',
  46      )
  47  );
  48  
  49  if ($unrecognized) {
  50      $unrecognized = implode("\n  ", $unrecognized);
  51      cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
  52  }
  53  
  54  if ($options['help']) {
  55      $help =
  56  "Execute periodic cron actions.
  57  
  58  Options:
  59  -h, --help            Print out this help
  60  -s, --stop            Notify all other running cron processes to stop after the current task
  61  
  62  Example:
  63  \$sudo -u www-data /usr/bin/php admin/cli/cron.php
  64  ";
  65  
  66      echo $help;
  67      die;
  68  }
  69  
  70  if ($options['stop']) {
  71      // By clearing the caches this signals to other running processes
  72      // to exit after finishing the current task.
  73      \core\task\manager::clear_static_caches();
  74      die;
  75  }
  76  
  77  \core\local\cli\shutdown::script_supports_graceful_exit();
  78  
  79  cron_run();