What I want to do :
User hit a url (ex: BASE-URL/download/json).
Code fetch huge data from database and stream it into a JSON file and user is promp
I was able to achieve what I wanted with the help of all the above comments.
Here is the code for the same.
$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;
It created a large file which I was able to download. Exactly what I wanted. Posting the solution so that it can help someone with same issue.