Adding better file locking in write(). This should reduce issues

with file locking and unserialize().
Fixes #1660
This commit is contained in:
0x20h 2011-05-10 20:27:01 +02:00 committed by Mark Story
parent b5a533b287
commit ea7c8c4710

View file

@ -136,13 +136,24 @@ class FileEngine extends CacheEngine {
}
}
if ($this->settings['lock']) {
$this->_File->lock = true;
}
$expires = time() + $duration;
$contents = $expires . $lineBreak . $data . $lineBreak;
$success = $this->_File->write($contents);
$this->_File->close();
if (!$handle = fopen($this->_File->path, 'c')) {
return false;
}
if ($this->settings['lock']) {
flock($handle, LOCK_EX);
}
$success = ftruncate($handle, 0) && fwrite($handle, $contents) && fflush($handle);
if ($this->settings['lock']) {
flock($handle, LOCK_UN);
}
fclose($handle);
return $success;
}