How Zend_Log prevent the race condition while writing a log message?

109 views Asked by At

I have looked into a little bit of the Zend_Log, which is a log module of Zend Framework, but I didn't see it using a flock function to prevent a race condition if there are multiple php script writing to the same file. As per what I know, the web application based on the zend framework treat each request as a individual php process, so the state can't be shared between those process, so keep a write file action in sync is necessary.

Does anyone know the reason why?

1

There are 1 answers

0
Matthewgao On

Let me answer my own question, after check some documents, in UNIX like system a O_APPEND opened file is thread and process safe to write to the file. But Windows is an exception, maybe php did some wrapper for a windows interpreter.

If a open file is PIPE or FIFO, then it's different from a pure file. If the size bytes exceed the size of PIPE_BUF, then it's not atomic.

Understanding concurrent file writes from multiple processes

O_APPEND document