|
Posted by Cabbar Duzayak on 10/19/40 11:13
Hi,
As the subject mentions, is fwrite method atomic in PHP? What I mean
by that is, does fwrite function acquire an implicit lock while
writing or do I need to explicitly acquire an EXCLUSIVE lock on the
file before I call fwrite?
The problem I am having is that, I want to track user requests by
logging simple request parameters such as user IP, request URI, etc.
instead of inserting into the db for avoiding overheads. And I will
have a cronjob read this data around midnight and write it into the
database (when there is little load on the server).
So, the questions I have is:
1. While writing this information, do I need to get an exclusive lock
before writing? Say I have a 200 bytes string, and 2 people call
fwrite at the same time with 2 strings, will they be written
sequentually or will it mix these strings depending on the O/S IO
buffer size.
2. While I am inserting this data into the database, I will have to
lock the file, dump them into the database and empty it. So, this
might make some users wait, which is something I am trying to avoid.
But, in anycase I will need to have a secondary lock object which
controls access to this log I guess, i.e. acquire secondary lock,
rename the file to .tmp or something, release the lock, and in the
meantime read from .tmp, parse it and put it in the db.
Any ideas?
Thanks...
Navigation:
[Reply to this message]
|