I have two different PHP files that both write to the same file. Each PHP script is called by a user action of two different HTML pages. I know it will be possible for the t
Please note:
As of PHP 5.3.2, the automatic unlocking when the file's resource handle is closed was removed. Unlocking now always has to be done manually.
The updated backward compatible code is:
if (($fp = fopen('locked_file', 'ab')) !== FALSE) {
if (flock($fp, LOCK_EX) === TRUE) {
fwrite($fp, "Write something here\n");
flock($fp, LOCK_UN);
}
fclose($fp);
}
i.e. you have to call flock(.., LOCK_UN) explicitly because fclose() does not do it anymore.