function process()
{
global $config, $phpEx, $phpbb_root_path, $user;
$lock = new \phpbb\lock\flock($this->cache_file);
$lock->acquire();
// avoid races, check file existence once
$have_cache_file = file_exists($this->cache_file);
if (!$have_cache_file || $config['last_queue_run'] > time() - $config['queue_interval']) {
if (!$have_cache_file) {
$config->set('last_queue_run', time(), false);
}
$lock->release();
return;
}
$config->set('last_queue_run', time(), false);
include $this->cache_file;
foreach ($this->queue_data as $object => $data_ary) {
@set_time_limit(0);
if (!isset($data_ary['package_size'])) {
$data_ary['package_size'] = 0;
}
$package_size = $data_ary['package_size'];
$num_items = !$package_size || sizeof($data_ary['data']) < $package_size ? sizeof($data_ary['data']) : $package_size;
/*
* This code is commented out because it causes problems on some web hosts.
* The core problem is rather restrictive email sending limits.
* This code is nly useful if you have no such restrictions from the
* web host and the package size setting is wrong.
// If the amount of emails to be sent is way more than package_size than we need to increase it to prevent backlogs...
if (sizeof($data_ary['data']) > $package_size * 2.5)
{
$num_items = sizeof($data_ary['data']);
}
*/
switch ($object) {
case 'email':
// Delete the email queued objects if mailing is disabled
if (!$config['email_enable']) {
unset($this->queue_data['email']);
continue 2;
}
break;
case 'jabber':
if (!$config['jab_enable']) {
unset($this->queue_data['jabber']);
continue 2;
}
include_once $phpbb_root_path . 'includes/functions_jabber.' . $phpEx;
$this->jabber = new jabber($config['jab_host'], $config['jab_port'], $config['jab_username'], htmlspecialchars_decode($config['jab_password']), $config['jab_use_ssl']);
if (!$this->jabber->connect()) {
$messenger = new messenger();
$messenger->error('JABBER', $user->lang['ERR_JAB_CONNECT']);
continue 2;
}
if (!$this->jabber->login()) {
$messenger = new messenger();
$messenger->error('JABBER', $user->lang['ERR_JAB_AUTH']);
continue 2;
}
break;
default:
$lock->release();
return;
}
for ($i = 0; $i < $num_items; $i++) {
// Make variables available...
extract(array_shift($this->queue_data[$object]['data']));
switch ($object) {
case 'email':
$err_msg = '';
$to = !$to ? 'undisclosed-recipients:;' : $to;
if ($config['smtp_delivery']) {
$result = smtpmail($addresses, mail_encode($subject), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $err_msg, $headers);
} else {
$result = phpbb_mail($to, $subject, $msg, $headers, PHP_EOL, $err_msg);
}
if (!$result) {
$messenger = new messenger();
$messenger->error('EMAIL', $err_msg);
continue 2;
}
break;
case 'jabber':
foreach ($addresses as $address) {
if ($this->jabber->send_message($address, $msg, $subject) === false) {
$messenger = new messenger();
$messenger->error('JABBER', $this->jabber->get_log());
continue 3;
}
}
break;
}
}
// No more data for this object? Unset it
if (!sizeof($this->queue_data[$object]['data'])) {
unset($this->queue_data[$object]);
}
// Post-object processing
switch ($object) {
case 'jabber':
// Hang about a couple of secs to ensure the messages are
// handled, then disconnect
$this->jabber->disconnect();
break;
}
}
if (!sizeof($this->queue_data)) {
@unlink($this->cache_file);
} else {
if ($fp = @fopen($this->cache_file, 'wb')) {
fwrite($fp, "<?php\nif (!defined('IN_PHPBB')) exit;\n\$this->queue_data = unserialize(" . var_export(serialize($this->queue_data), true) . ");\n\n?>");
fclose($fp);
if (function_exists('opcache_invalidate')) {
@opcache_invalidate($this->cache_file);
}
try {
$this->filesystem->phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE);
} catch (\phpbb\filesystem\exception\filesystem_exception $e) {
// Do nothing
}
}
}
$lock->release();
}