title: Running out of memory during CSV file creation
body: <p>I have a report that I have to write code to run, it has to compile a month's worth of data into a CSV file. The data is something close to 112,000 lines long and 47 cells of data per line.</p>
  
  <p>I'm running out of memory as I try to write the file. I thought something with <code>fflush</code> might do it but it doesn't seem to. The code is in PHP.</p>
  
  <pre><code>$filename = str_replace(array('-',':','_', ' '), '', "export_" . date("m-d-Y H:i:s") . ".csv");
  header('Content-Type: text/csv');
  header("Content-Disposition: attachment; filename='$filename'");
  header('Pragma: no-cache');
  header('Expires: 0');
  $con=mysqli_connect("localhost","root","changedForSecurity","reports");
  // Check connection
  if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
  
  $result = mysqli_query($con,"SELECT * FROM testing");
  $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
  $fp = fopen($filename, 'w');
  $i=1;
  while($row = mysqli_fetch_array($result)) {
  
      if ($i &lt; 15000) {
          fputcsv($fp, $row);
          $i++;
      } else {
          fflush($fp);
          $i=1;
          fputcsv($fp, $row);
      }
  
  }
  </code></pre>