PHP flock() alternative

后端 未结 7 1793
一个人的身影
一个人的身影 2020-12-09 11:40

PHP\'s documentation page for flock() indicates that it\'s not safe to use under IIS. If I can\'t rely on flock under all circumstances, is there another way I

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 11:49

    I appreciate this question is a few years old but I kinda felt that a working example/replacement for flock might be worth building. I've based this on the other answers but for someone who is purely looking to replace the flock functionality (rather than write a file at the same time (although this does reflect the PHP manual flock example)) I believe the following will suffice

    function my_flock ($path,$release = false){
        if ($release){
            @rmdir($path);
        } else {
            return !file_exists($path) && @mkdir($path);
        }
    }
    

提交回复
热议问题