title: Locking NFS files in PHP
body: <p>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 <em>can</em> 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.</p>
  
  <p><code>flock(...)</code> 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.</p>
  
  <p>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.</p>
  
  <p>Any better ideas?</p>
  
  <p>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.</p>