diff options
-rw-r--r-- | phpBB/cron.php | 32 | ||||
-rw-r--r-- | phpBB/docs/CHANGELOG.html | 1 | ||||
-rw-r--r-- | phpBB/install/database_update.php | 1 |
3 files changed, 34 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 diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html index ad6e443d4b..56133a3a59 100644 --- a/phpBB/docs/CHANGELOG.html +++ b/phpBB/docs/CHANGELOG.html @@ -277,6 +277,7 @@ p a { <li>[Fix] Quick-Mod tools now retaining the start parameter (Bug #13537)</li> <li>[Fix] Several fixes for custom profile fields on multi-lingual boards (Bugs #13763, #13527, #13525, #11515)</li> <li>[Fix] Return to the mode previously selected after disaproving a post (Bug #13796)</li> + <li>[Fix] Cron now uses a locking variable to make sure it does not spawn too many webserver processes (Bug #12741)</li> </ul> </div> diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 395eefc1f1..d255688f55 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1233,6 +1233,7 @@ if (version_compare($current_version, '3.0.RC3', '<=')) $db->sql_query($sql); set_config('allow_birthdays', '1'); + set_config('cron_lock', '0', true); } _write_result($no_updates, $errored, $error_ary); |