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.
/admin/ -> cron.php (source)

Differences Between: [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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   * Web 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   * This file is best run from cron on the host system (ie outside PHP).
  26   * It is strongly recommended to add password protection via admin settings.
  27   *
  28   * eg   wget -q -O /dev/null 'http: *moodle.somewhere.edu/admin/cron.php?password=SeCreT666'
  29   *
  30   * It is also possible to use CLI script admin/cli/cron.php instead,
  31   * you can not call this script from command line any more.
  32   *
  33   * @package    core
  34   * @subpackage admin
  35   * @copyright  1999 onwards Martin Dougiamas  http://dougiamas.com
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  
  39  
  40  if (defined('STDIN')) {
  41      fwrite(STDERR, "ERROR: This script no longer supports CLI, please use admin/cli/cron.php instead\n");
  42      exit(1);
  43  }
  44  
  45  // This is a fake CLI script, it is a really ugly hack which emulates
  46  // CLI via web interface, please do not use this hack elsewhere
  47  define('CLI_SCRIPT', true);
  48  define('WEB_CRON_EMULATED_CLI', 'defined'); // ugly ugly hack, do not use elsewhere please
  49  define('NO_OUTPUT_BUFFERING', true);
  50  
  51  require('../config.php');
  52  require_once($CFG->libdir.'/clilib.php');
  53  require_once($CFG->libdir.'/cronlib.php');
  54  
  55  // extra safety
  56  \core\session\manager::write_close();
  57  
  58  // check if execution allowed
  59  if (!empty($CFG->cronclionly)) {
  60      // This script can only be run via the cli.
  61      print_error('cronerrorclionly', 'admin');
  62      exit;
  63  }
  64  // This script is being called via the web, so check the password if there is one.
  65  if (!empty($CFG->cronremotepassword)) {
  66      $pass = optional_param('password', '', PARAM_RAW);
  67      if ($pass != $CFG->cronremotepassword) {
  68          // wrong password.
  69          print_error('cronerrorpassword', 'admin');
  70          exit;
  71      }
  72  }
  73  
  74  // send mime type and encoding
  75  @header('Content-Type: text/plain; charset=utf-8');
  76  
  77  // we do not want html markup in emulated CLI
  78  @ini_set('html_errors', 'off');
  79  
  80  // execute the cron
  81  cron_run();