5
* @version $Id: cron.php,v 1.21 2007/10/05 14:30:06 acydburn Exp $
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
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
16
$phpEx = substr(strrchr(__FILE__, '.'), 1);
17
include($phpbb_root_path . 'common.' . $phpEx);
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($config['cron_lock']))
39
set_config('cron_lock', '0', true);
42
// make sure cron doesn't run multiple times in parallel
43
if ($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(' ', $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($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() - $config['queue_interval'] <= $config['last_queue_run'] || !file_exists($phpbb_root_path . 'cache/queue.' . $phpEx))
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 && !$config['smtp_delivery'])
85
$use_shutdown_function = false;
88
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
91
if ($use_shutdown_function)
93
register_shutdown_function(array(&$queue, 'process'));
104
if (time() - $config['cache_gc'] <= $config['cache_last_gc'] || !method_exists($cache, 'tidy'))
109
if ($use_shutdown_function)
111
register_shutdown_function(array(&$cache, 'tidy'));
122
// Select the search method
123
$search_type = basename($config['search_type']);
125
if (time() - $config['search_gc'] <= $config['search_last_gc'] || !file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
130
include_once("{$phpbb_root_path}includes/search/$search_type.$phpEx");
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() - $config['warnings_gc'] <= $config['warnings_last_gc'])
159
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
161
if ($use_shutdown_function)
163
register_shutdown_function('tidy_warnings');
172
case 'tidy_database':
174
if (time() - $config['database_gc'] <= $config['database_last_gc'])
179
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
181
if ($use_shutdown_function)
183
register_shutdown_function('tidy_database');
192
case 'tidy_sessions':
194
if (time() - $config['session_gc'] <= $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.' . $phpEx);
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);
b'\\ No newline at end of file'