file_put_contents('test.txt',$data,FILE_APPEND|LOCK_EX);
Such as the above statement, if a large amount of data is being written to a file, it will take a long time, and subsequent file_put_contents must also be written to the file Input data, since the file has an exclusive lock, will subsequent file_put_contents become a queue to wait for the completion of the previous file write operation
file_put_contents('test.txt',$data,FILE_APPEND|LOCK_EX);
Such as the above statement, if a large amount of data is being written to a file, it will take a long time, and subsequent file_put_contents must also be written to the file Input data, since the file has an exclusive lock, will subsequent file_put_contents become a queue to wait for the completion of the previous file write operation
Yes, the implementation of file_put_contents is actually a simple implementation of the set of operations of fopen, fwrite, fflush, and fclose. If LOCK_EX is added, fopen will also execute a flock, and then this code will block until the file lock is released before continuing to execute. This waiting is sorted in a queue.
In addition, writing too large files may exceed the maximum execution event of PHP, and there is a risk of losing data. If the data is important to you, it is recommended to implement a large-volume write queue by yourself