title: file locking in php
body: <p>I had a newcomer (the next door teenager) write some php code to track some usage on my web site. I'm not familiar with php so I'm asking a bit about concurrent file access.</p>
  
  <p>My native app (on Windows), occasionally logs some data to my site by hitting the URL that contains my php script. The native app does not examine the returned data.</p>
  
  <pre><code>        $fh = fopen($updateFile, 'a') or die("can't open file");
          fwrite($fh, $ip);
          fwrite($fh, ', ');
          fwrite($fh, $date);
          fwrite($fh, ', ');
          fwrite($fh, implode(', ', $_GET));
          fwrite($fh, "\r\n");
          fclose($fh);
  </code></pre>
  
  <p>This is a low traffic site, and the data is not critical. But what happens if two users collide and two instances of the script each try to add a line to the file? Is there any implicit file locking in php?</p>
  
  <p>Is the code above at least safe from locking up and never returning control to my user? Can the file get corrupted?  If I have the script above delete the file every month, what happens if another instance of the script is in the middle of writing to the file?</p>