aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/cron.php
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2007-07-25 17:58:39 +0000
committerNils Adermann <naderman@naderman.de>2007-07-25 17:58:39 +0000
commitd54b42a04b377ae0d3b6b1d327326eca17dbe528 (patch)
tree42b9a581c08b8e7c1ed8c488545d6318859695fc /phpBB/cron.php
parent4ca00cba39a0169bd521cbe7e9bd24d3bf3c1cd2 (diff)
downloadforums-d54b42a04b377ae0d3b6b1d327326eca17dbe528.tar
forums-d54b42a04b377ae0d3b6b1d327326eca17dbe528.tar.gz
forums-d54b42a04b377ae0d3b6b1d327326eca17dbe528.tar.bz2
forums-d54b42a04b377ae0d3b6b1d327326eca17dbe528.tar.xz
forums-d54b42a04b377ae0d3b6b1d327326eca17dbe528.zip
- cron now uses a locking variable to make sure it does not spawn too many webserver processes [Bug #12741]
git-svn-id: file:///svn/phpbb/trunk@7947 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/cron.php')
-rw-r--r--phpBB/cron.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/phpBB/cron.php b/phpBB/cron.php
index ea4c4ddef2..6c7b4311aa 100644
--- a/phpBB/cron.php
+++ b/phpBB/cron.php
@@ -33,6 +33,33 @@ echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==
// test without flush ;)
// flush();
+// make sure cron doesn't run multiple times in parallel
+if ($config['cron_lock'])
+{
+ // if the other process is running more than an hour already we have to assume it
+ // aborted without cleaning the lock
+ $time = explode(' ', $config['cron_lock']);
+ $time = $time[0];
+
+ if ($time + 3600 >= time())
+ {
+ exit;
+ }
+}
+
+define('CRON_ID', time() . ' ' . unique_id());
+
+$sql = 'UPDATE ' . CONFIG_TABLE . "
+ SET config_value = '" . $db->sql_escape(CRON_ID) . "'
+ WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape($config['cron_lock']) . "'";
+$db->sql_query($sql);
+
+// another cron process altered the table between script start and UPDATE query so exit
+if ($db->sql_affectedrows() != 1)
+{
+ exit;
+}
+
/**
* Run cron-like action
* Real cron-based layer will be introduced in 3.2
@@ -227,6 +254,11 @@ else
garbage_collection();
}
+$sql = 'UPDATE ' . CONFIG_TABLE . "
+ SET config_value = '0'
+ WHERE config_name = 'cron_lock' AND config_value = '" . $db->sql_escape(CRON_ID) . "'";
+$db->sql_query($sql);
+
exit;
?> \ No newline at end of file