/phpBB/cron.php

https://github.com/dellsystem/phpbb3 · PHP · 108 lines · 71 code · 14 blank · 23 comment · 9 complexity · 32a0d57eda63f355a8ce4f0c19ec2e1e MD5 · raw file

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