文件锁

 程序独占该文件,不允许其他操作,直到该程序完成对文件的操作

1
$content = ' 2   asdfasdfasdf 3   asdfasdfasdf 4   asdfasdfasd 5   asdfasdf 6   asdfasdf 7 ';

 1 $file = '/var/www/file.txt'; 

1 $fp = @fopen($file, 'wb') ;
2 if(@feof($file)) return; 
3 flock($fp, LOCK_EX);
4 $len = @fwrite($fp, $content);
5 flock($fp, LOCK_UN);
6 @fclose($fp);
7 exec("chmod 777 $file");

posted @ 2019-03-06 10:01  终究是乌云遮了天  阅读(216)  评论(0编辑  收藏  举报