Test if file is locked

后端 未结 2 519
自闭症患者
自闭症患者 2020-12-09 12:50

In PHP, how can I test if a file has already been locked with flock? For example, if another running script has called the following:

$fp = fopen(\'thefile.t         


        
2条回答
  •  我在风中等你
    2020-12-09 13:14

    Check it like this:

    if (!flock($file, LOCK_EX)) {
        throw new Exception(sprintf('File %s is locked', $file));
    }
    
    fwrite($file, $write_contents);
    

提交回复
热议问题