title: How to keep a file open in PHP?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2234239/file-resource-persistence-in-php">File resource persistence in PHP</a>  </p>
  </blockquote>
  
  
  
  <p>If using <code>fopen</code> for opening a file, it will be closed and unset at the end of the PHP script even without <code>fclose</code>.</p>
  
  <pre><code>$fp = fopen('data.txt', 'w');
  fwrite($fp, 'text');
  fclose($fp);
  </code></pre>
  
  <p>Now if it is a frequently used script, we need to open/close the file with the filesystem too many times (file I/O). It would be better to keep the file open. This is the technique that database systems use.</p>
  
  <p>Is there a function in PHP to leave a file open and do not re-open it on the next run?</p>
  
  <p>Or How we can setup a semi-server to keep a file opened for frequent access by PHP?</p>