File_put_contents(&%039%test.txt & #039;, $ data, FILE_APPEND | LOCK_EX); the preceding statement takes a long time to write a large amount of data to a file, the subsequent file_put_contents will also write data to the file. because the file has an exclusive lock, the subsequent file_put...
File_put_contents('test.txt ', $ data, FILE_APPEND | LOCK_EX );
The preceding statement takes a long time to write a large amount of data to a file. the subsequent file_put_contents will also write data to the file because the file has exclusive locks, will the subsequent file_put_contents become a queue waiting for the write operation of the previous file to be completed?
Reply content:
File_put_contents('test.txt ', $ data, FILE_APPEND | LOCK_EX );
The preceding statement takes a long time to write a large amount of data to a file. the subsequent file_put_contents will also write data to the file because the file has exclusive locks, will the subsequent file_put_contents become a queue waiting for the write operation of the previous file to be completed?
Yes. the implementation of file_put_contents is actually a simple implementation of the fopen, fwrite, fflush, and fclose operations. If LOCK_EX is added, a flock will be executed after fopen, and the code will be blocked until it is locked. This wait is sorted by queue.
In addition, writing too large files may exceed the maximum execution event of PHP, posing a risk of data loss. if data is important to you, we recommend that you implement a large data write queue.