How does LOCK work to write logs to a flat file?

Reading concurrency flat files is almost unlimited (correct me if I am wrong); but how is concurrency to write? Consider a simple access log entry (for visits) in PHP to add a string of access information completed with\n

fopen(); // in append mode
fwrite();
fclose();

Since we have concurrent visitors, how does the system (one user who is a user of wbserver / php) record view logs at the same time?

My misunderstanding: a function file_put_contents()(which is a shell of three functions) has the ability to lock ( LOCK_EX)? Is this blocking option useful? How will this affect the journal entry?

UPDATE: My question is about how LOCKing initially works / affects logging to a file. I do not compare file_put_contentsand fwrite; even my question is not limited PHP. The issue is locking the file during the recording process.

+5
source share
2 answers

file_put_contents()has the ability to lock, but in my opinion you should use flock().

From the manual:

Available flags

FILE_USE_INCLUDE_PATH
Find the file name in the include directory. See Include_path for more information. Information.

FILE_APPEND If a file name already exists, add data to the file, rather than overwrite it.

LOCK_EX .

flock() :

LOCK_SH, ().
LOCK_EX, ().
LOCK_UN, ( ).

: http://php.net/manual/en/function.flock.php : http://php.net/manual/en/function.file-put-contents.php

+3

, - , . , ? , ? .

, ? , .

https://github.com/Seldaek/monolog

0

All Articles