Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Description
Symfony version(s) affected
7.0.0
Description
Downloading a file using BinaryFileResponse can result in reaching the max execution time of php.
File starts downloading fine and finishes in the middle of the download without any error. But the file wasn't fully downloaded, due to the script reaching max execution time.
If the connection of the client is fast enough, this is not an issue.
We had an example of a 50MB file, which for me downloaded in no time and all worked well. Another client with only 1MB/s and the default 30s max execution time only downloaded 30MB. Chrome didn't showed an error and all looked fine, but the file was corrupted and couldn't be unpacked (was a zip file generated in another process)
How to reproduce
set_time_limit(5);$response =newBinaryFileResponse($fileInfo);$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT,$fileInfo['filename'] .'.' .$fileInfo['extension']);return$response;
Either limit download speed or download a file large enough to ecxeed the limit of 5s (in example).
Possible Solution
We increased the max_execution_time using set_time_limit inside the controller for now, but I think that maybe the set_time_limit should be maybe insideBinaryFileResponse::sendContent
loop, so reset the timer after some chunks are send - probably not every chunk.
Additional Context
No response