Will file_put_contents queue up and wait when it encounters a file exclusive lock?

WBOY
Release: 2016-10-17 09:30:16
Original
2215 people have browsed it

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

Reply content:

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!