时间:2021-07-01 10:21:17 帮助过:2人阅读
$fh = fopen($path, "r+");
if( flock($fh, LOCK_EX) ){//加写锁
$old_content=json_decode(fread($fh,filesize($path)),true);
$old_content=$old_content.$new_content;
ftruncate($fh,0); // 将文件截断到给定的长度
rewind($fh); // 倒回文件指针的位置
fwrite($fh,json_encode($old_content));
// @chmod($path,0644);
flock($fh, LOCK_UN); //解锁
}
fclose($fh);
http://www.bkjia.com/PHPjc/743151.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/743151.htmlTechArticle 代码如下:
$fh = fopen($path, "r+"); if( flock($fh, LOCK_EX) ){//加写锁 $old_content=json_decode(fread($fh,filesize($path)),true); $old_content=$old_content.$new...