From ec15ac92f3935e08bbdb42db57586fb12a67be55 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 12 Mar 2011 14:29:34 +0100 Subject: [PATCH 1/4] [ticket/10046] Remove calls to register_shutdown_function() in cron.php After reading some PHP source as well as the PHP manual we have arrived at the following two situations with one conclusion: * SAPI supports flush(): o call to flush() is enough to stop the page from displaying as loading o and thus register_shutdown_function is unnecessary * SAPI does not support flush(): o neither a call to flush() nor the beginning of shutdown phase, which calls registered shutdown functions can flush anything to the client o and thus register_shutdown_function is unnecessary Thanks to lacton for reporting the initial issue. Thanks to nn- and naderman for doing all the dirty works. PHPBB3-10046 --- phpBB/cron.php | 91 ++++++-------------------------------------------- 1 file changed, 10 insertions(+), 81 deletions(-) diff --git a/phpBB/cron.php b/phpBB/cron.php index 3993a149b5..16880b8914 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -21,7 +21,6 @@ $user->session_begin(false); $auth->acl($user->data); $cron_type = request_var('cron_type', ''); -$use_shutdown_function = (@function_exists('register_shutdown_function')) ? true : false; // Output transparent gif header('Cache-Control: no-cache'); @@ -79,23 +78,10 @@ switch ($cron_type) break; } - // A user reported using the mail() function while using shutdown does not work. We do not want to risk that. - if ($use_shutdown_function && !$config['smtp_delivery']) - { - $use_shutdown_function = false; - } - include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); $queue = new queue(); - if ($use_shutdown_function) - { - register_shutdown_function(array(&$queue, 'process')); - } - else - { - $queue->process(); - } + $queue->process(); break; @@ -106,14 +92,7 @@ switch ($cron_type) break; } - if ($use_shutdown_function) - { - register_shutdown_function(array(&$cache, 'tidy')); - } - else - { - $cache->tidy(); - } + $cache->tidy(); break; @@ -138,14 +117,7 @@ switch ($cron_type) break; } - if ($use_shutdown_function) - { - register_shutdown_function(array(&$search, 'tidy')); - } - else - { - $search->tidy(); - } + $search->tidy(); break; @@ -158,14 +130,7 @@ switch ($cron_type) include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx); - if ($use_shutdown_function) - { - register_shutdown_function('tidy_warnings'); - } - else - { - tidy_warnings(); - } + tidy_warnings(); break; @@ -178,14 +143,7 @@ switch ($cron_type) include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx); - if ($use_shutdown_function) - { - register_shutdown_function('tidy_database'); - } - else - { - tidy_database(); - } + tidy_database(); break; @@ -196,14 +154,7 @@ switch ($cron_type) break; } - if ($use_shutdown_function) - { - register_shutdown_function(array(&$user, 'session_gc')); - } - else - { - $user->session_gc(); - } + $user->session_gc(); break; @@ -230,26 +181,12 @@ switch ($cron_type) if ($row['prune_days']) { - if ($use_shutdown_function) - { - register_shutdown_function('auto_prune', $row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']); - } - else - { - auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']); - } + auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']); } if ($row['prune_viewed']) { - if ($use_shutdown_function) - { - register_shutdown_function('auto_prune', $row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']); - } - else - { - auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']); - } + auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']); } } @@ -257,16 +194,8 @@ switch ($cron_type) } // Unloading cache and closing db after having done the dirty work. -if ($use_shutdown_function) -{ - register_shutdown_function('unlock_cron'); - register_shutdown_function('garbage_collection'); -} -else -{ - unlock_cron(); - garbage_collection(); -} +unlock_cron(); +garbage_collection(); exit; From 79d209824f9d88fa8116ace1a14d25900ed9466f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 12 Mar 2011 14:40:20 +0100 Subject: [PATCH 2/4] [ticket/10046] Call flush() in cron.php PHPBB3-10046 --- phpBB/cron.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/phpBB/cron.php b/phpBB/cron.php index 16880b8914..8000066c92 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -29,10 +29,9 @@ header('Content-length: 43'); echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='); -// test without flush ;) -// flush(); +// Flush here to prevent browser from showing the page as loading while running cron. +flush(); -// if (!isset($config['cron_lock'])) { set_config('cron_lock', '0', true); From a8f2e79fbc485c0133e616068570ed369e23935c Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 12 Mar 2011 14:40:42 +0100 Subject: [PATCH 3/4] [ticket/10046] No longer change $phpbb_root_path to an absolute path for cron. This is no longer required because we no longer call register_shutdown_function() which made this change necessary. PHPBB3-10046 --- phpBB/common.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index c8b2fb9609..ae174c8441 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -118,11 +118,6 @@ else define('STRIP', (get_magic_quotes_gpc()) ? true : false); } -if (defined('IN_CRON')) -{ - $phpbb_root_path = dirname(__FILE__) . DIRECTORY_SEPARATOR; -} - if (file_exists($phpbb_root_path . 'config.' . $phpEx)) { require($phpbb_root_path . 'config.' . $phpEx); From 9a4804525471b69b1ed0beb4ea7145faeb8855b8 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 2 Mar 2011 06:43:10 -0500 Subject: [PATCH 4/4] [ticket/10046] Do not link bots to cron.php. Bots, generally speaking, will not request cron.php immediately, thus telling them to request it is pointless. PHPBB3-10046 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 6a2d132175..80b51f80ae 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4611,7 +4611,7 @@ function page_footer($run_cron = true) // Call cron-type script $call_cron = false; - if (!defined('IN_CRON') && $run_cron && !$config['board_disable']) + if (!defined('IN_CRON') && $run_cron && !$config['board_disable'] && !$user->data['is_bot']) { $call_cron = true; $time_now = (!empty($user->time_now) && is_int($user->time_now)) ? $user->time_now : time();