Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/IniReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,20 @@ private function getFileContent($filename)
if (!$handle) {
return false;
}

// Ensuring we have a shared lock to avoid race conditions when another process is writing to the file.
$flockRetries = 0;
while (true) {
if (flock($handle, LOCK_SH)) {
break;
}
if ($flockRetries >= 20) {
throw new Exception("Timeout after trying to get a shared lock on file $filename.");
}
usleep(100 * 1000);
$flockRetries++;
}

$ini = fread($handle, filesize($filename));
fclose($handle);
return $ini;
Expand Down