我已经阅读了PHP手册,并了解flock可能无法在FAT环境中运行。
<?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");
}
?>
你会做点什么吗?你会改变什么?谢谢!