Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 3, 2022
1 parent b8b7fe8 commit 1da4588
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/SafeStream/SafeStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ public function stream_open(string $path, string $mode, int $options): bool
return false;
}

if ($resMode === 'r' && !fstat($handle)['size']) { // re-take lock if file is empty
flock($handle, LOCK_UN);
usleep(10);
flock($handle, LOCK_SH);
if ($resMode === 'r') { // re-take lock if file is empty
$counter = 10;
while ($counter-- && !fstat($handle)['size']) {
flock($handle, LOCK_UN);
usleep(1);
flock($handle, LOCK_SH);
}
}

if ($mode[0] === 'a') {
Expand Down

0 comments on commit 1da4588

Please sign in to comment.