Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Prevent race condition on writing cache files
Browse files Browse the repository at this point in the history
When multiple people first access a ZF2 powered website there is the possibility that both requests write simultaneously write a slightly different file to disk. The result can be an PHP file having a parse error.

This commit fixes this by acquiring an exclusive lock.
  • Loading branch information
Roel van Duijnhoven authored Feb 17, 2017
1 parent f22ec38 commit bb8d19f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Listener/AbstractListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function setOptions(ListenerOptions $options)
protected function writeArrayToFile($filePath, $array)
{
$content = "<?php\nreturn " . var_export($array, 1) . ';';
file_put_contents($filePath, $content);
file_put_contents($filePath, $content, LOCK_EX);
return $this;
}
}

0 comments on commit bb8d19f

Please sign in to comment.