Read concurrency of flat files is almost unlimited (correct me if I'm wrong); but how is the concurrency for write? Consider a simple access log writing (for visits) in PHP as to append a line of access detail ended with \n
fopen(); // in append mode
fwrite();
fclose();
Since we have concurrent visitors, how the system (one user which is the wbserver/php user) write the view logs concurrently?
My confusion is: the function file_put_contents()
(which is a wrapper of the above three functions) has an option for locking (LOCK_EX
)? Is it beneficial to use this locking option? How this will affect the log writing?
UPDATE: My question is about how LOCK
ing originally works/affects writing log to file. I do not compare file_put_contents
and fwrite
; even my question is not limited to PHP
. The question is about locking a file during write process.