Copy code The code is as follows:
$fh = fopen($path, "r+");
if( flock($fh, LOCK_EX) ){//Add write lock
$old_content=json_decode(fread($fh,filesize($path)),true);
$old_content=$old_content.$ new_content;
ftruncate($fh,0); // Truncate the file to the given length
rewind($fh); // Rewind the position of the file pointer
fwrite($fh,json_encode( $old_content));
// @chmod($path,0644);
flock($fh, LOCK_UN); //Unlock
}
fclose($fh);
http://www.bkjia.com/PHPjc/743151.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/743151.htmlTechArticleCopy the code The code is as follows: $fh = fopen($path, "r+"); if( flock($fh , LOCK_EX) ){//Add write lock $old_content=json_decode(fread($fh,filesize($path)),true); $old_content=$old_content.$new...