Locking NFS files in PHP
Posted
by Oli
on Stack Overflow
See other posts from Stack Overflow
or by Oli
Published on 2008-10-20T13:36:04Z
Indexed on
2010/05/21
2:00 UTC
Read the original article
Hit count: 367
php
|concurrency
Part of my latest webapp needs to write to file a fair amount as part of its logging. One problem I've noticed is that if there are a few concurrent users, the writes can overwrite each other (instead of appending to file). I assume this is because of the destination file can be open in a number of places at the same time.
flock(...)
is usually superb but it doesn't appear to work on NFS... Which is a huge problem for me as the production server uses a NFS array.
The closest thing I've seen to an actual solution involves trying to create a lock dir and waiting until it can be created. To say this lacks elegance is understatement of the year, possibly decade.
Any better ideas?
Edit: I should add that I don't have root on the server and doing the storage in another way isn't really feasible any time soon, not least within my deadline.
© Stack Overflow or respective owner