root / trunk / phpBB / cron.php
History | View | Annotate | Download (2.4 kB)
| 1 | <?php
|
|---|---|
| 2 | /**
|
| 3 | * |
| 4 | * @package phpBB3 |
| 5 | * @copyright (c) 2005 phpBB Group |
| 6 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | /**
|
| 11 | */ |
| 12 | define('IN_PHPBB', true); |
| 13 | define('IN_CRON', true); |
| 14 | $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; |
| 15 | $phpEx = substr(strrchr(__FILE__, '.'), 1); |
| 16 | include($phpbb_root_path . 'common.' . $phpEx); |
| 17 | |
| 18 | // Do not update users last page entry
|
| 19 | $user->session_begin(false); |
| 20 | $auth->acl($user->data); |
| 21 | |
| 22 | function output_image() |
| 23 | {
|
| 24 | // Output transparent gif
|
| 25 | header('Cache-Control: no-cache'); |
| 26 | header('Content-type: image/gif'); |
| 27 | header('Content-length: 43'); |
| 28 | |
| 29 | echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='); |
| 30 | |
| 31 | // Flush here to prevent browser from showing the page as loading while
|
| 32 | // running cron.
|
| 33 | flush();
|
| 34 | } |
| 35 | |
| 36 | function do_cron($cron_lock, $run_tasks) |
| 37 | {
|
| 38 | global $config; |
| 39 | |
| 40 | foreach ($run_tasks as $task) |
| 41 | {
|
| 42 | if (defined('DEBUG_EXTRA') && $config['use_system_cron']) |
| 43 | {
|
| 44 | echo "[phpBB cron] Running task '{$task->get_name()}'\n"; |
| 45 | } |
| 46 | |
| 47 | $task->run();
|
| 48 | } |
| 49 | |
| 50 | // Unloading cache and closing db after having done the dirty work.
|
| 51 | $cron_lock->release();
|
| 52 | garbage_collection(); |
| 53 | } |
| 54 | |
| 55 | // Thanks to various fatal errors and lack of try/finally, it is quite easy to leave
|
| 56 | // the cron lock locked, especially when working on cron-related code.
|
| 57 | //
|
| 58 | // Attempt to alleviate the problem by doing setup outside of the lock as much as possible.
|
| 59 | //
|
| 60 | // If DEBUG_EXTRA is defined and cron lock cannot be obtained, a message will be printed.
|
| 61 | |
| 62 | if ($config['use_system_cron']) |
| 63 | {
|
| 64 | $cron = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver()); |
| 65 | } |
| 66 | else
|
| 67 | {
|
| 68 | $cron_type = request_var('cron_type', ''); |
| 69 | |
| 70 | // Comment this line out for debugging so the page does not return an image.
|
| 71 | output_image(); |
| 72 | } |
| 73 | |
| 74 | $cron_lock = new phpbb_lock_db('cron_lock', $config, $db); |
| 75 | if ($cron_lock->acquire()) |
| 76 | {
|
| 77 | if ($config['use_system_cron']) |
| 78 | {
|
| 79 | $run_tasks = $cron->find_all_ready_tasks(); |
| 80 | } |
| 81 | else
|
| 82 | {
|
| 83 | // If invalid task is specified, empty $run_tasks is passed to do_cron which then does nothing
|
| 84 | $run_tasks = array(); |
| 85 | $task = $cron->find_task($cron_type); |
| 86 | if ($task) |
| 87 | {
|
| 88 | if ($task->is_parametrized()) |
| 89 | {
|
| 90 | $task->parse_parameters($request); |
| 91 | } |
| 92 | if ($task->is_ready()) |
| 93 | {
|
| 94 | $run_tasks = array($task); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | do_cron($cron_lock, $run_tasks); |
| 100 | } |
| 101 | else
|
| 102 | {
|
| 103 | if (defined('DEBUG_EXTRA')) |
| 104 | {
|
| 105 | echo "Could not obtain cron lock.\n"; |
| 106 | } |
| 107 | } |

