Automatic installer lang files (20101011)
[moodle.git] / admin / cron.php
blob51b34aecc4d374f04121b846dd25d7a3aa0c6b68
1 <?php
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.
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/>.
18 /**
19 * Web cron
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.
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.
28 * eg wget -q -O /dev/null 'http: *moodle.somewhere.edu/admin/cron.php?password=SeCreT666'
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.
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
39 // This is a fake CLI script, it is a really ugly hack which emulates
40 // CLI via web interface, please do not use this hack elsewhere
41 define('CLI_SCRIPT', true);
42 define('WEB_CRON_EMULATED_CLI', 'defined'); // ugly ugly hack, do not use elsewhere please
44 require('../config.php');
45 require_once($CFG->libdir.'/clilib.php');
46 require_once($CFG->libdir.'/cronlib.php');
48 // disable compression, it would prevent closing of buffers
49 if (ini_get('zlib.output_compression')) {
50 ini_set('zlib.output_compression', 'Off');
52 // no more headers and buffers
53 ob_implicit_flush(true);
54 while(ob_get_level()) {
55 if (!ob_end_clean()) {
56 // prevent infinite loop
57 break;
61 // extra safety
62 session_get_instance()->write_close();
64 // check if execution allowed
65 if (!empty($CFG->cronclionly)) {
66 // This script can only be run via the cli.
67 print_error('cronerrorclionly', 'admin');
68 exit;
70 // This script is being called via the web, so check the password if there is one.
71 if (!empty($CFG->cronremotepassword)) {
72 $pass = optional_param('password', '', PARAM_RAW);
73 if ($pass != $CFG->cronremotepassword) {
74 // wrong password.
75 print_error('cronerrorpassword', 'admin');
76 exit;
80 // send mime type and encoding
81 if (check_browser_version('MSIE')) {
82 //ugly IE hack to work around downloading instead of viewing
83 @header('Content-Type: text/html; charset=utf-8');
84 echo "<xmp>"; //<pre> is not good enough for us here
85 } else {
86 //send proper plaintext header
87 @header('Content-Type: text/plain; charset=utf-8');
90 // execute the cron
91 cron_run();
93 // finish the IE hack
94 if (check_browser_version('MSIE')) {
95 echo "</xmp>";