I have read the PHP manual and understand that flock may not work in FAT environment.
<?php
// assign file
$file = "testfile";
$content = "test";
// check whether file is lock? If so, wait.
while(file_exists($file . ".lock"))
{
usleep(500000);
}
if (!file_exists($file . ".lock"))
{
// lock the file before writing to file
$fl = fopen("$file.lock","w");
fwrite($fl,"");
// write to file
$fp = fopen("$file", "r+");
fwrite($fp, $content);
fclose($fp);
// unlock file
fclose($fl);
unlink($file . ".lock");
}
?>
Would you do anything differently? What would you change? Thanks!