[ticket/9061] Simplify conditional statements by reworking the logic.

PHPBB3-9061
This commit is contained in:
Chris Smith 2010-09-09 20:05:11 +01:00
parent 01ef46a510
commit 9819700247

View file

@ -647,25 +647,31 @@ class queue
{ {
$mode = 'wb'; $mode = 'wb';
} }
$lock_fp = @fopen($this->cache_file . '.lock', $mode); $lock_fp = @fopen($this->cache_file . '.lock', $mode);
// Two processes may attempt to create lock file at the same time.
// Have the losing process try opening the lock file again for reading if ($mode == 'wb')
// on the assumption that the winning process created it
if (!$lock_fp && $mode == 'wb')
{ {
// Assign to $mode for the check in chmod below if (!$lock_fp)
$mode = 'rb'; {
$lock_fp = @fopen($this->cache_file . '.lock', $mode); // Two processes may attempt to create lock file at the same time.
} // Have the losing process try opening the lock file again for reading
if ($lock_fp && $mode == 'wb') // on the assumption that the winning process created it
{ $mode = 'rb';
// Only need to set mode when the lock file is written $lock_fp = @fopen($this->cache_file . '.lock', $mode);
@chmod($this->cache_file . '.lock', 0666); }
else
{
// Only need to set mode when the lock file is written
@chmod($this->cache_file . '.lock', 0666);
}
} }
if ($lock_fp) if ($lock_fp)
{ {
@flock($lock_fp, LOCK_EX); @flock($lock_fp, LOCK_EX);
} }
return $lock_fp; return $lock_fp;
} }