Large File Stream breaks off

Hi,

I am relatively new to SLIM. Had already found some posts on the subject of large file download and actually also implemented it “successfully”. If the files are smaller than ~ 250 MB the download works without problems.

If the file is bigger, the curl download just stops. Strange is, if the file has a size of 500MB, curl is creating a file of 750 MB and stops.

Here is my code.

$this->get('/downloadFile', function (Request $request, Response $response, array $args) {
   //$path = 'C:\temp\wsusscn2.cab'; //large file
   $path = 'C:\temp\avira.exe';  //small file
 
   $fh = fopen($path, 'rb');
   $file_stream = new Stream($fh);
            
  return $response->withBody($file_stream)
            ->withHeader('Content-Disposition', 'attachment; filename=avira.exe;')
            ->withHeader('Content-Type', mime_content_type($path))
            ->withHeader('Content-Length', filesize($path));
  })->setOutputBuffering(false);       
curl https://127.0.0.1/api/v2/downloadFile --output C:\Temp\wsusscn2.cab --insecure
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
 68  544M   68  371M    0     0  11.0M      0  0:00:49  0:00:33  0:00:16 11.1M
 68  544M   68  373M    0     0  2006k      0  0:04:37  0:03:10  0:01:27     0
curl: (56) OpenSSL SSL_read: Connection was reset, errno 10054

curl https://127.0.0.1/api/v2/downloadFile --output C:\Temp\avira.exe --insecure
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 5418k  100 5418k    0     0  7451k      0 --:--:-- --:--:-- --:--:-- 7463k

I had already searched the forum, but unfortunately did not find a solution.

Would be happy about support.

Eric

It could be a PHP memory limit or a server memory limit.

I tried to increase everything on the test system, without success.
I also increased the request timelimit in IIS.

A direct curl download to the file, works like a charm.

Tried configurations:

max_execution_time = 90000
max_input_time = 90000
memory_limit = 4048M
and
max_execution_time = 0
max_input_time = 0
memory_limit = 4048M

Ok I solved the problem.

No changes required to the default php configuration.
The problem was related to the IIS FasCGI timeout settings.

Thanks

1 Like