Skip to content

Should BinaryFileResponse reset max execution time? #53721

@attrib

Description

@attrib

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 = new BinaryFileResponse($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 inside BinaryFileResponse::sendContent loop, so reset the timer after some chunks are send - probably not every chunk.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions