Skip to content

Commit 76a813b

Browse files
author
arcfieldOSS
committed
Advisory Lock to prevent partial reads
Updating file driver to prevent partial reads during write (will also modify abstract.php)
1 parent cafc8b4 commit 76a813b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

phpfastcache/3.0.0/drivers/files.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,14 @@ function driver_set($keyword, $value = "", $time = 300, $option = array() ) {
8888

8989
if($toWrite == true) {
9090
try {
91-
$f = @fopen($file_path, "w+");
92-
fwrite($f, $data);
91+
$f = @fopen($file_path, "c");
92+
if (flock($f,LOCK_EX| LOCK_NB)) { //got a lock to write;
93+
fwrite($f, $data);
94+
fflush($f);
95+
flock($f,LOCK_UN);
96+
} else {
97+
//arguably the file is being written to so the job is done
98+
}
9399
fclose($f);
94100
} catch (Exception $e) {
95101
// miss cache

0 commit comments

Comments
 (0)