PHP的文件锁定

The core of my app fetch content using curl and i wish to cache content that are frequently fetched.I open the file using at the end of headers in my CURLOPT_HEADERFUNCTION callback and will write the write the data to cache in the CURLOPT_WRITEFUNCTION callback.I will then close the file at the end of the request(bytes == content_length)

file_put_contents is highly inefficient in the situation as demonstrated by this thread.

Now suppose 2 users want to fetch the same content(Process A & B).Assume process A has locked the file and is writing.

1.Can process B still read from the file ? The operation should be LOCK_EX|LOCK_SH if i am not mistaken.

2.If processes can read or write to a same file at the same time , what happens when process B has already read all data , does it wait for process A to write to file?.

Let me know how i can improve my strategy.

P.S I am on Centos 7 OS