title: Keeping a file handler open over a long period of time in PHP
body: <p>I am using PHP 7.1 (if it makes any difference), and I am looking for possible issues with opening a file handler with fopen, but closing that file handler a long time after (potentially 30+ minutes).</p>
  
  <p>The scenario comes down to a long running script that logs its actions periodically. Right now, I use a simple process of using file_put_contents with FILE_APPEND. It works. But it slows down over time as the file gets bigger and bigger.</p>
  
  <p>Using fopen and fwrite means I can avoid that slow-down. The only issue is that I wouldnt be calling fclose until the end of the scripts execution. I assume constantly fopen/fclose'ing the file will give me the same poor performance as my current implementation. </p>
  
  <p>Any one have experience with the internals in this regard? I have no need to read the file, only write.</p>
  
  <p>EDIT:
  More info: I am currently running this in a Linux VM on my laptop (VirtualBox). I do not expect top notch performance from this setup. That being said, I still notice the slow-down as the log file gets bigger and bigger.</p>
  
  <p>My code logic as as simple as:</p>
  
  <pre><code>while(true)
  {
      $result = someFunction();
      if(!$result)
      {
          logSomething();
      }
      else
      {
          break;
      }
  }
  </code></pre>
  
  <p>The frequency of writes is several times a second.</p>
  
  <p>And files can become several GBs in size.</p>