diff options
| author | Andreas Fischer <bantu@phpbb.com> | 2012-12-04 20:26:43 +0100 |
|---|---|---|
| committer | Andreas Fischer <bantu@phpbb.com> | 2012-12-04 20:26:43 +0100 |
| commit | 2fdd039e5223b7acea3795811326945bd649bf49 (patch) | |
| tree | b0efba74b1bdc2eaad2443d7e65f61c66ee66a1e /phpBB/includes/functions_messenger.php | |
| parent | d7a23df2d9c3a9f93d8477e164edef0d263d8dcb (diff) | |
| parent | 3e093c282a63df4d16b212859fd8137fd2bbca81 (diff) | |
| download | forums-2fdd039e5223b7acea3795811326945bd649bf49.tar forums-2fdd039e5223b7acea3795811326945bd649bf49.tar.gz forums-2fdd039e5223b7acea3795811326945bd649bf49.tar.bz2 forums-2fdd039e5223b7acea3795811326945bd649bf49.tar.xz forums-2fdd039e5223b7acea3795811326945bd649bf49.zip | |
Merge remote-tracking branch 'p/ticket/10103' into develop
* p/ticket/10103:
[ticket/10103] New and improved wording.
[ticket/10103] Assert with messages.
[ticket/10103] assertLessThan/assertGreaterThan.
[ticket/10103] Inline assignment is bad?
[ticket/10103] $rv had too few characters.
[ticket/10103] Correct flock class documentation.
[ticket/10103] Try a longer sleep for travis.
[ticket/10103] Convert the rest of the tree to flock class.
[ticket/10103] Test for flock lock class, with concurrency no less.
[ticket/10103] Use flock lock class in messenger.
[ticket/10103] Factor out flock lock class.
Diffstat (limited to 'phpBB/includes/functions_messenger.php')
| -rw-r--r-- | phpBB/includes/functions_messenger.php | 72 |
1 files changed, 8 insertions, 64 deletions
diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index cf03de08c4..56fc7e628f 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -651,64 +651,6 @@ class queue } /** - * Obtains exclusive lock on queue cache file. - * Returns resource representing the lock - */ - function lock() - { - // For systems that can't have two processes opening - // one file for writing simultaneously - if (file_exists($this->cache_file . '.lock')) - { - $mode = 'rb'; - } - else - { - $mode = 'wb'; - } - - $lock_fp = @fopen($this->cache_file . '.lock', $mode); - - if ($mode == 'wb') - { - if (!$lock_fp) - { - // Two processes may attempt to create lock file at the same time. - // Have the losing process try opening the lock file again for reading - // on the assumption that the winning process created it - $mode = 'rb'; - $lock_fp = @fopen($this->cache_file . '.lock', $mode); - } - else - { - // Only need to set mode when the lock file is written - @chmod($this->cache_file . '.lock', 0666); - } - } - - if ($lock_fp) - { - @flock($lock_fp, LOCK_EX); - } - - return $lock_fp; - } - - /** - * Releases lock on queue cache file, using resource obtained from lock() - */ - function unlock($lock_fp) - { - // lock() will return null if opening lock file, and thus locking, failed. - // Accept null values here so that client code does not need to check them - if ($lock_fp) - { - @flock($lock_fp, LOCK_UN); - fclose($lock_fp); - } - } - - /** * Process queue * Using lock file */ @@ -716,13 +658,14 @@ class queue { global $db, $config, $phpEx, $phpbb_root_path, $user; - $lock_fp = $this->lock(); + $lock = new phpbb_lock_flock($this->cache_file); + $lock->acquire(); set_config('last_queue_run', time(), true); if (!file_exists($this->cache_file) || filemtime($this->cache_file) > time() - $config['queue_interval']) { - $this->unlock($lock_fp); + $lock->release(); return; } @@ -789,7 +732,7 @@ class queue break; default: - $this->unlock($lock_fp); + $lock->release(); return; } @@ -865,7 +808,7 @@ class queue } } - $this->unlock($lock_fp); + $lock->release(); } /** @@ -878,7 +821,8 @@ class queue return; } - $lock_fp = $this->lock(); + $lock = new phpbb_lock_flock($this->cache_file); + $lock->acquire(); if (file_exists($this->cache_file)) { @@ -905,7 +849,7 @@ class queue phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE); } - $this->unlock($lock_fp); + $lock->release(); } } |
