How to upload (stream) large files in symfony2

What I want to do:
User hit the URL (ex: BASE-URL / download / json).
The code extracts huge data from the database and stream into a JSON file, and the user is prompted to download this file.

What I tried:
Created a large (700 MB) JSON file. I tried to open it with the code, but the error was thrown.

file_get_contents ($ file)

Mistake:

The allowed memory size in XXX bytes has been exhausted (tried to allocate YYY bytes)

I work in symfony2. Data can be up to 700 MB in size. Cannot increase allocated memory. How can i achieve this? Please comment if any further information is required.

+4
1

, , .
.

$response = new StreamedResponse();  
$i = -999999;  
$response->setCallback(function () {  
    while($i < 999999){  
        echo '{"G1ello":"hualala"}';  
        $i = $i + 1;  
    }  
});  
$filename = "Data.json";  
$contentDisposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename);
$response->headers->set('Content-Type', 'application/json');
$response->headers->set('Content-Disposition', $contentDisposition);
return $response;

, . , . , - .

+6

Source: https://habr.com/ru/post/1609440/


All Articles