moved the queue call, added interval. The current lock is very "fluent" at the moment. ;)

git-svn-id: file:///svn/phpbb/trunk@4068 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2003-05-30 06:37:07 +00:00
parent d4cbbb1055
commit 18ccaf4483
4 changed files with 32 additions and 13 deletions

View file

@ -229,6 +229,17 @@ if (time() - $config['cache_interval'] >= $config['cache_last_gc'])
} }
*/ */
// Handle queue.
if (time() - $config['queue_interval'] >= $config['last_queue_run'])
{
if (file_exists($phpbb_root_path . 'cache/queue.' . $phpEx))
{
include($phpbb_root_path . 'includes/emailer.'.$phpEx);
$queue = new Queue();
$queue->process();
}
}
// Show 'Board is disabled' message // Show 'Board is disabled' message
if ($config['board_disable'] && !defined('IN_ADMIN') && !defined('IN_LOGIN')) if ($config['board_disable'] && !defined('IN_ADMIN') && !defined('IN_LOGIN'))
{ {

View file

@ -502,13 +502,20 @@ class Queue
echo "</pre>;"; echo "</pre>;";
} }
// Thinking about a lock file...
function process() function process()
{ {
global $_SERVER, $_ENV; global $_SERVER, $_ENV, $db;
if (file_exists($this->cache_file)) if (file_exists($this->cache_file))
{ {
include($this->cache_file); include($this->cache_file);
$fp = @fopen($this->cache_file, 'r');
@flock($fp, LOCK_EX);
}
else
{
return;
} }
foreach ($this->queue_data as $object => $data_array) foreach ($this->queue_data as $object => $data_array)
@ -550,11 +557,15 @@ class Queue
if (count($this->queue_data) == 0) if (count($this->queue_data) == 0)
{ {
@flock($fp, LOCK_UN);
fclose($fp);
unlink($this->cache_file); unlink($this->cache_file);
} }
else else
{ {
$file = '<?php $this->queue_data=' . $this->format_array($this->queue_data) . '; ?>'; $file = '<?php $this->queue_data=' . $this->format_array($this->queue_data) . '; ?>';
@flock($fp, LOCK_UN);
fclose($fp);
if ($fp = @fopen($this->cache_file, 'wb')) if ($fp = @fopen($this->cache_file, 'wb'))
{ {
@ -564,6 +575,11 @@ class Queue
fclose($fp); fclose($fp);
} }
} }
$sql = "UPDATE " . CONFIG_TABLE . "
SET config_value = '" . time() . "'
WHERE config_name = 'last_queue_run'";
$db->sql_query();
} }
function save() function save()
@ -581,9 +597,9 @@ class Queue
} }
} }
$file = '<?php $this->queue_data=' . $this->format_array($this->data) . '; ?>'; $file = '<?php $this->queue_data = ' . $this->format_array($this->data) . '; ?>';
if ($fp = @fopen($this->cache_file, 'wb')) if ($fp = @fopen($this->cache_file, 'wt'))
{ {
@flock($fp, LOCK_EX); @flock($fp, LOCK_EX);
fwrite($fp, $file); fwrite($fp, $file);
@ -592,7 +608,6 @@ class Queue
} }
} }
// From acm_file.php
function format_array($array) function format_array($array)
{ {
$lines = array(); $lines = array();

View file

@ -47,15 +47,6 @@ if ($mark_read == 'forums')
trigger_error($message); trigger_error($message);
} }
// Handle queue - to be placed into common.php ? I think to only check and process at the index is enough. ;)
// Do not initiate the object, we do not need to do this...
if (file_exists($phpbb_root_path . 'cache/queue.' . $phpEx))
{
include($phpbb_root_path . 'includes/emailer.'.$phpEx);
$queue = new Queue();
$queue->process();
}
// Set some stats, get posts count from forums data if we... hum... retrieve all forums data // Set some stats, get posts count from forums data if we... hum... retrieve all forums data
$total_posts = $config['num_posts']; $total_posts = $config['num_posts'];
$total_topics = $config['num_topics']; $total_topics = $config['num_topics'];

View file

@ -65,6 +65,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('load_db_lastread',
INSERT INTO phpbb_config (config_name, config_value) VALUES ('load_db_track', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('load_db_track', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('session_gc', '3600'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('session_gc', '3600');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_gc', '7200'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_gc', '7200');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('queue_interval', '600');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('ip_check', '4'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('ip_check', '4');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('browser_check', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('browser_check', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('version', '2.1.1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('version', '2.1.1');
@ -134,6 +135,7 @@ INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('num_po
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('num_topics', '1', 1); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('num_topics', '1', 1);
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('session_last_gc', '0', 1); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('session_last_gc', '0', 1);
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('search_last_gc', '0', 1); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('search_last_gc', '0', 1);
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('last_queue_run', '0', 1);
# -- auth options # -- auth options
INSERT INTO phpbb_auth_options (auth_option, is_local) VALUES ('f_', 1); INSERT INTO phpbb_auth_options (auth_option, is_local) VALUES ('f_', 1);