I created a function to store settings to a file (in a readable way) so that the settings can be modified by directly editing the file later on.
I used the method described here.
$data = "<?php return ".var_export($var, true).";";
file_put_contents($filename, $data);
seems to work fine when there are lower no of requests making the changes to the file, but when there are multiple simultaneous requests the file contents are filled with syntax errors or wrong orders of contents and sometimes it remains empty.
I tried using file_get_conents(..)
with third argument LOCK_EX and fwrite()
after using flock()
but that too resulted in same weird behaviour. What is happening here and how can I correct it ?