6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
13 define('IN_PHPBB', true);
14 define('IN_CRON', true);
15 if (!defined('PHPBB_ROOT_PATH')) define('PHPBB_ROOT_PATH', './');
16 if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__
, '.'), 1));
17 include(PHPBB_ROOT_PATH
. 'common.' . PHP_EXT
);
19 // Do not update users last page entry
20 $user->session_begin(false);
21 $auth->acl($user->data
);
23 $cron_type = request_var('cron_type', '');
24 $use_shutdown_function = (@function_exists
('register_shutdown_function')) ?
true : false;
26 // Output transparent gif
27 header('Cache-Control: no-cache');
28 header('Content-type: image/gif');
29 header('Content-length: 43');
31 echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
33 // test without flush ;)
37 if (!isset(phpbb
::$config['cron_lock']))
39 set_config('cron_lock', '0', true);
42 // make sure cron doesn't run multiple times in parallel
43 if (phpbb
::$config['cron_lock'])
45 // if the other process is running more than an hour already we have to assume it
46 // aborted without cleaning the lock
47 $time = explode(' ', phpbb
::$config['cron_lock']);
50 if ($time +
3600 >= time())
56 define('CRON_ID', time() . ' ' . unique_id());
58 $sql = 'UPDATE ' . CONFIG_TABLE
. "
59 SET config_value = '" . $db->sql_escape(CRON_ID
) . "'
60 WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape(phpbb
::$config['cron_lock']) . "'";
63 // another cron process altered the table between script start and UPDATE query so exit
64 if ($db->sql_affectedrows() != 1)
70 * Run cron-like action
71 * Real cron-based layer will be introduced in 3.2
77 if (time() - phpbb
::$config['queue_interval'] <= phpbb
::$config['last_queue_run'] ||
!file_exists(PHPBB_ROOT_PATH
. 'cache/queue.' . PHP_EXT
))
82 // A user reported using the mail() function while using shutdown does not work. We do not want to risk that.
83 if ($use_shutdown_function && !phpbb
::$config['smtp_delivery'])
85 $use_shutdown_function = false;
88 include_once(PHPBB_ROOT_PATH
. 'includes/functions_messenger.' . PHP_EXT
);
91 if ($use_shutdown_function)
93 register_shutdown_function(array(&$queue, 'process'));
104 if (time() - phpbb
::$config['cache_gc'] <= phpbb
::$config['cache_last_gc'] ||
!method_exists(phpbb
::$acm, 'tidy'))
109 if ($use_shutdown_function)
111 register_shutdown_function(array(&phpbb
::$acm, 'tidy'));
122 // Select the search method
123 $search_type = basename(phpbb
::$config['search_type']);
125 if (time() - phpbb
::$config['search_gc'] <= phpbb
::$config['search_last_gc'] ||
!file_exists(PHPBB_ROOT_PATH
. 'includes/search/' . $search_type . '.' . PHP_EXT
))
130 include_once(PHPBB_ROOT_PATH
. "includes/search/$search_type." . PHP_EXT
);
132 // We do some additional checks in the module to ensure it can actually be utilised
134 $search = new $search_type($error);
141 if ($use_shutdown_function)
143 register_shutdown_function(array(&$search, 'tidy'));
152 case 'tidy_warnings':
154 if (time() - phpbb
::$config['warnings_gc'] <= phpbb
::$config['warnings_last_gc'])
159 include_once(PHPBB_ROOT_PATH
. 'includes/functions_admin.' . PHP_EXT
);
161 if ($use_shutdown_function)
163 register_shutdown_function('tidy_warnings');
172 case 'tidy_database':
174 if (time() - phpbb
::$config['database_gc'] <= phpbb
::$config['database_last_gc'])
179 include_once(PHPBB_ROOT_PATH
. 'includes/functions_admin.' . PHP_EXT
);
181 if ($use_shutdown_function)
183 register_shutdown_function('tidy_database');
192 case 'tidy_sessions':
194 if (time() - phpbb
::$config['session_gc'] <= phpbb
::$config['session_last_gc'])
199 if ($use_shutdown_function)
201 register_shutdown_function(array(&$user, 'session_gc'));
212 $forum_id = request_var('f', 0);
214 $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq
215 FROM ' . FORUMS_TABLE
. "
216 WHERE forum_id = $forum_id";
217 $result = $db->sql_query($sql);
218 $row = $db->sql_fetchrow($result);
219 $db->sql_freeresult($result);
226 // Do the forum Prune thang
227 if ($row['prune_next'] < time() && $row['enable_prune'])
229 include_once(PHPBB_ROOT_PATH
. 'includes/functions_admin.' . PHP_EXT
);
231 if ($row['prune_days'])
233 if ($use_shutdown_function)
235 register_shutdown_function('auto_prune', $row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']);
239 auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']);
243 if ($row['prune_viewed'])
245 if ($use_shutdown_function)
247 register_shutdown_function('auto_prune', $row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']);
251 auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']);
259 // Unloading cache and closing db after having done the dirty work.
260 if ($use_shutdown_function)
262 register_shutdown_function('unlock_cron');
263 register_shutdown_function('garbage_collection');
268 garbage_collection();
277 function unlock_cron()
281 $sql = 'UPDATE ' . CONFIG_TABLE
. "
282 SET config_value = '0'
283 WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape(CRON_ID
) . "'";
284 $db->sql_query($sql);