title: PHP fopen() memory efficiency and usage
body: <p>I am building a system to create files that will range from a few Kb to say, around 50Mb, and this question is more out of curiosity than anything else. I couldn't find any answers online.</p>
  
  <p>If I use </p>
  
  <pre><code>$handle=fopen($file,'w');
  </code></pre>
  
  <p>where is the $handle stored before I call</p>
  
  <pre><code>fclose($handle);
  </code></pre>
  
  <p>? Is it stored in the system's memory, or in a temp file somewhere?</p>
  
  <p>Secondly, I am building the file using a loop that takes 1024 bytes of data at a time, and each time writes data as:</p>
  
  <pre><code>fwrite($handle, $content);
  </code></pre>
  
  <p>It then calls </p>
  
  <pre><code>fclose($handle);
  </code></pre>
  
  <p>when the loop is complete and all data is written. However, would it be more efficient or memory friendly to use a loop that did</p>
  
  <pre><code>$handle = fopen($file, 'a');
  fwrite($handle, $content);
  fclose($handle);
  </code></pre>
  
  <p>?</p>