'Response binary file takes too much time - Symfony 5 REST API

Symfony 5 as REST API on a linux server (it's a shared host with cpanel).

I have a really simple endpoint that it is to download private files based on user privileges. The problem is that the endpoint takes too much time, i.e. for a 15MB .rar file the request took 45 seconds.

The response is:

    use Symfony\Component\HttpFoundation\BinaryFileResponse;

    $response = new BinaryFileResponse($path);

    $response->headers->set('Cache-Control', 'private');
    $response->headers->set('Content-Type', 'application/x-rar-compressed');
    $response->headers->set('Content-Disposition', $response->headers->makeDisposition(
        ResponseHeaderBag::DISPOSITION_ATTACHMENT,
        $filename
    ));

    return $response;

And the problem effectively is in the file response, because if I change the response, for example, to this:

use Symfony\Component\HttpFoundation\JsonResponse;    

$response = new JsonResponse();
return $response->setData([
    'success' => true
]);

Request took 0.5/0.8 seconds.

I need to know if the time it takes is normal or because it is a shared server.

And the type of response is ok? All the files are .rar and rarely exceed 20MB



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source