Skip to content

Commit a262341

Browse files
author
arcfieldOSS
committed
Use Advisory Lock on Read
Prevent partial reads during writing while using the file driver.
1 parent 76a813b commit a262341

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

phpfastcache/3.0.0/abstract.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,13 @@ protected function readfile($file) {
280280
throw new Exception("Can't Read File",96);
281281

282282
}
283-
while (!feof($file_handle)) {
284-
$line = fgets($file_handle);
285-
$string .= $line;
283+
if (flock($file_handle, LOCK_SH | LOCK_NB)) {
284+
while (!feof($file_handle)) {
285+
$line = fgets($file_handle);
286+
$string .= $line;
287+
}
288+
} else {
289+
throw new Exception("Can't Read File",96);
286290
}
287291
fclose($file_handle);
288292

@@ -424,4 +428,4 @@ protected function __setChmodAuto() {
424428
}
425429

426430

427-
}
431+
}

0 commit comments

Comments
 (0)