Php 如何在FAT系统中实现锁定机制?
我已经阅读了PHP手册,了解flock可能无法在FAT环境中工作Php 如何在FAT系统中实现锁定机制?,php,flock,Php,Flock,我已经阅读了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")) { // loc
<?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");
}
?>
你会做些不同的事情吗?你会改变什么?谢谢 Symfony只需释放其锁组件,无需重新发明轮子对不起,我不是PHP专家。尝试在使用fat系统的局域网中实现它。这行得通吗?你的方法似乎很直截了当,为什么行不通呢?不管怎样,谁还在用脂肪我正在一个由Synology NAS支持的局域网中实现我的代码,Synology NAS运行在FAT文件系统上。谢谢你的评论。:)