Search code examples
windowsapachefilesizelimit

Apache2 on Windows fails downloading large files (>34M)


I'm trying to set up an Apache2 webserver with PHP on Windows. I'm using the EasyPHP package to install the required servers. Everything works fine as long as I want to host larger files for downloads. By large I mean 34M. When I try to download such a file, the request times out. If I try to download a smaller file with the same filename, it works. I have no idea what could cause this. I try to access the files directly on the server, but also fails if I try to fetch with some PHP code. I have LimitRequestBody set to 0 in httpd.conf and I can't find any option that might has an effect on this.

EDIT: The download fails when no PHP is used, and I'm trying to download the file with direct link. So I don't really think it's a problem related to PHP, rather to apache.

Any help would be appreciated.


Solution

  • I found the answer for this here: https://serverfault.com/questions/115906/is-there-some-limit-on-a-size-of-a-file-when-force-downloading-it-with-php-on-ap

    The memory limit didn't help, but using the readfile_chunked function worked! Thank you from here too!

    <?php 
    function readfile_chunked ($filename) { 
      $chunksize = 1*(1024*1024); // how many bytes per chunk 
      $buffer = ''; 
      $handle = fopen($filename, 'rb'); 
      if ($handle === false) { 
        return false; 
      } 
      while (!feof($handle)) { 
        $buffer = fread($handle, $chunksize); 
        print $buffer; 
      } 
      return fclose($handle); 
    } 
    ?>