From 18ccaf44831f9c18d8cf74ea280ea31d36cc8bac Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Fri, 30 May 2003 06:37:07 +0000 Subject: [PATCH] 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 --- phpBB/common.php | 11 +++++++++++ phpBB/includes/emailer.php | 23 +++++++++++++++++++---- phpBB/index.php | 9 --------- phpBB/install/schemas/mysql_basic.sql | 2 ++ 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index c30742eb9c..36d0d3377f 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -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 if ($config['board_disable'] && !defined('IN_ADMIN') && !defined('IN_LOGIN')) { diff --git a/phpBB/includes/emailer.php b/phpBB/includes/emailer.php index 0f6a08d6de..8deba01c4d 100755 --- a/phpBB/includes/emailer.php +++ b/phpBB/includes/emailer.php @@ -502,13 +502,20 @@ class Queue echo ";"; } + // Thinking about a lock file... function process() { - global $_SERVER, $_ENV; + global $_SERVER, $_ENV, $db; if (file_exists($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) @@ -550,11 +557,15 @@ class Queue if (count($this->queue_data) == 0) { + @flock($fp, LOCK_UN); + fclose($fp); unlink($this->cache_file); } else { $file = 'queue_data=' . $this->format_array($this->queue_data) . '; ?>'; + @flock($fp, LOCK_UN); + fclose($fp); if ($fp = @fopen($this->cache_file, 'wb')) { @@ -564,6 +575,11 @@ class Queue fclose($fp); } } + + $sql = "UPDATE " . CONFIG_TABLE . " + SET config_value = '" . time() . "' + WHERE config_name = 'last_queue_run'"; + $db->sql_query(); } function save() @@ -581,9 +597,9 @@ class Queue } } - $file = 'queue_data=' . $this->format_array($this->data) . '; ?>'; + $file = '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); fwrite($fp, $file); @@ -592,7 +608,6 @@ class Queue } } - // From acm_file.php function format_array($array) { $lines = array(); diff --git a/phpBB/index.php b/phpBB/index.php index 6947b2d677..f47a78c19c 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -47,15 +47,6 @@ if ($mark_read == 'forums') 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 $total_posts = $config['num_posts']; $total_topics = $config['num_topics']; diff --git a/phpBB/install/schemas/mysql_basic.sql b/phpBB/install/schemas/mysql_basic.sql index ce7ab8974b..e8c02f1f8d 100644 --- a/phpBB/install/schemas/mysql_basic.sql +++ b/phpBB/install/schemas/mysql_basic.sql @@ -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 ('session_gc', '3600'); 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 ('browser_check', '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 ('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 ('last_queue_run', '0', 1); # -- auth options INSERT INTO phpbb_auth_options (auth_option, is_local) VALUES ('f_', 1);