[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
This commit is contained in:
Andreas Fischer 2011-03-12 14:29:34 +01:00
parent 2f57bfb6f2
commit ec15ac92f3

View file

@ -21,7 +21,6 @@ $user->session_begin(false);
$auth->acl($user->data); $auth->acl($user->data);
$cron_type = request_var('cron_type', ''); $cron_type = request_var('cron_type', '');
$use_shutdown_function = (@function_exists('register_shutdown_function')) ? true : false;
// Output transparent gif // Output transparent gif
header('Cache-Control: no-cache'); header('Cache-Control: no-cache');
@ -79,23 +78,10 @@ switch ($cron_type)
break; 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); include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
$queue = new queue(); $queue = new queue();
if ($use_shutdown_function) $queue->process();
{
register_shutdown_function(array(&$queue, 'process'));
}
else
{
$queue->process();
}
break; break;
@ -106,14 +92,7 @@ switch ($cron_type)
break; break;
} }
if ($use_shutdown_function) $cache->tidy();
{
register_shutdown_function(array(&$cache, 'tidy'));
}
else
{
$cache->tidy();
}
break; break;
@ -138,14 +117,7 @@ switch ($cron_type)
break; break;
} }
if ($use_shutdown_function) $search->tidy();
{
register_shutdown_function(array(&$search, 'tidy'));
}
else
{
$search->tidy();
}
break; break;
@ -158,14 +130,7 @@ switch ($cron_type)
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx); include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
if ($use_shutdown_function) tidy_warnings();
{
register_shutdown_function('tidy_warnings');
}
else
{
tidy_warnings();
}
break; break;
@ -178,14 +143,7 @@ switch ($cron_type)
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx); include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
if ($use_shutdown_function) tidy_database();
{
register_shutdown_function('tidy_database');
}
else
{
tidy_database();
}
break; break;
@ -196,14 +154,7 @@ switch ($cron_type)
break; break;
} }
if ($use_shutdown_function) $user->session_gc();
{
register_shutdown_function(array(&$user, 'session_gc'));
}
else
{
$user->session_gc();
}
break; break;
@ -230,26 +181,12 @@ switch ($cron_type)
if ($row['prune_days']) if ($row['prune_days'])
{ {
if ($use_shutdown_function) auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']);
{
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']);
}
} }
if ($row['prune_viewed']) if ($row['prune_viewed'])
{ {
if ($use_shutdown_function) auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']);
{
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']);
}
} }
} }
@ -257,16 +194,8 @@ switch ($cron_type)
} }
// Unloading cache and closing db after having done the dirty work. // Unloading cache and closing db after having done the dirty work.
if ($use_shutdown_function) unlock_cron();
{ garbage_collection();
register_shutdown_function('unlock_cron');
register_shutdown_function('garbage_collection');
}
else
{
unlock_cron();
garbage_collection();
}
exit; exit;