diff --git a/src/SafeStream/SafeStream.php b/src/SafeStream/SafeStream.php index 1eea8b8..609b7c0 100644 --- a/src/SafeStream/SafeStream.php +++ b/src/SafeStream/SafeStream.php @@ -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') {