如何在FAT系统中实现锁机制?

时间:2017-03-23 12:38:05

标签: 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"))
{
    // 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");
}

?>

你会做点什么吗?你会改变什么?谢谢!

0 个答案:

没有答案