Out of memory (allocated 4194304) (tried to allocate 265278080 bytes) Symfony 3, PHP Version 7.1.20-1, remote server
Within my Symfony 3 project. I have the following controller, to let an user to download a .pdf file
public function basicAction(Request $request)
{
$filename = $request->server->get('DOCUMENT_ROOT')."/bundles/myPath/".$pdfFile->getPath();
// Generate response
$response = new Response();
// Set headers
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', 'application/pdf');
$response->headers->set('Content-Disposition', 'attachment; filename="' . basename($filename) . '";');
$response->headers->set('Content-length', filesize($filename));
// set_time_limit(0); //does not help
// ini_set('memory_limit', '-1'); //does not help
$response->setContent(file_get_contents($filename));
return $response;
}
}
Everthing works fine on my local install (on a Fedora machine). On my production server (Linux Debian-91-stretch-64-LAMP 4.9.0-8-amd6), everything works fine too, as long as a user try to download a small size .pdf file. For a 266MB file, I get the following error:
[2018-12-03 00:12:17] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\OutOfMemoryException: "Error: Out of memory (allocated 4194304) (tried to allocate 265278080 bytes)" at /var/www/...myPath.../Controller/MyDownloadController.php line 87 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\OutOfMemoryException(code: 0): Error: Out of memory (allocated 4194304) (tried to allocate 265278080 bytes) at /var/www/...myPath.../Controller/MyDownloadController.php:87)"} []
I get the error even if I try to set memory_limit
at 3G.
I guess it depends on a limit on the remote (virtual) server, but I am not sure how to check it.
Comments
Post a Comment