title: Creating ZIP File in PHP coming up with Browser errors, not Script errors
body: <p>I created a code to backup an entire website &amp; automatically download it on a single click. Here is what my code looks like:</p>
  
  <pre><code>if (file_exists("file.zip")) {
    unlink("file.zip");
  }
  $folder_array = array();
  $file_array = array();
  function listFolderFiles($dir){
    global $folder_array;
    global $file_array;
    $ffs = scandir($dir);
    foreach($ffs as $ff){
      if ($ff != '.' &amp;&amp; $ff != '..') {
        if (is_dir($dir.'/'.$ff)) {
          $new_item = "$dir/$ff";
          $new_item = str_replace('..//','',$new_item);
          if ($new_item !== "stats") {
            array_push($folder_array, $new_item);
            listFolderFiles($dir.'/'.$ff);
          }
        }
        else {
          $new_item = "$dir/$ff";
          $new_item = str_replace('..//','',$new_item);
          if (($new_item !== "stats/logs") &amp;&amp; ($new_item !== "stats/")) {
            array_push($file_array, $new_item);
          }
        }
      }
    }
  }
  listFolderFiles('../');
  $zip = new ZipArchive;
  if ($zip-&gt;open('file.zip', true ? ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE) === TRUE) {
    foreach($folder_array as $folder) {
      $zip-&gt;addEmptyDir($folder);
    }
    foreach($file_array as $key =&gt; $file) {
      $file_path = "../$file";
      $zip-&gt;addFile($file_path, $file);
    }
  }
  $zip-&gt;close();
  $file = "file.zip";
  chmod("$file", 0700);
  header("Content-type: application/zip");
  header("Content-Disposition: attachment; filename=". $file);
  readfile($file);
  </code></pre>
  
  <p>Now this code was working good for awhile, but it seems today it doesn't want to work. The thing is, it's not a PHP script error. I've checked my error logs and nothing is showing up. It appears to be a browser error, but each browser displays a different message:</p>
  
  <p>Chrome says "This webpage is not available"
  Firefox says "The connection was reset"
  Internet Explorer says "This page can't be displayed"</p>
  
  <p>Even though these errors come up, the ZIP file is still being created and I can download it from the server.</p>
  
  <p>Here is a list of things I've tried after extensive research:</p>
  
  <p>1) I removed the code to have the ZIP file download automatically (all code written after I close the ZIP file). Still get the browser errors.</p>
  
  <p>2) I read that it's possible too many files are getting opened and its going over my limit. I added to the code to close and reopen the ZIP file after every 200 files. Still didn't work.</p>
  
  <p>3) I limited the amount of files to ZIP. Everything was working fine below 500. Between 500 to 1,000 files, the code would work a partial amount of the time. Sometimes it would go through fine, the others it would give me the browser error. After 1,000 or so it just wouldn't work properly at all.</p>
  
  <p>The hosting is through GoDaddy.</p>
  
  <p>PHP Version is 5.2.17</p>
  
  <p>max_execution_time is set at 240 (the code never goes this long, usually only takes about 30 sec to run)</p>
  
  <p>memory_limit is set at 500M (more than twice the size of all the files combined)</p>
  
  <p>I'm at a loss, I really don't know what is going on because this code was working just fine for 1,500 files a few weeks ago. And again, the ZIP file is still being created, there are no PHP errors and it's only the Browsers that are coming back with these errors.</p>