【发布时间】:2020-04-26 12:24:22
【问题描述】:
我有一个 Symfony 4 应用程序,我在其中上传限制为 2MB 的文件,此限制有效,在开发环境中一切正常,图像上传良好,但在 prod 中,我总是有相同的消息:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in /var/www/html/asso.issoire-web.fr/vendor/symfony/debug/Exception/OutOfMemoryException.php on line 1
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36864 bytes) in /var/www/html/asso.issoire-web.fr/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 108
这行是问题
$file->move($this->getParameter($path), $name);
它在我的资产中移动图像以便我在视图中恢复它,我修改了 php.ini 中的 memory_limit = -1,并且 upload_max_filesize = 200M post_max_size = 200M
但是还是同样的问题导致图片无法上传,请问有解决办法吗?
我指定所有这些都在 VPS 上
更新:
这是生产中有问题的代码
if($form->isSubmitted() && $form->isValid()) {
$path = 'upload_directory';
// Récupère les valeurs sous formes d'objet profil
$profil = $form->getData();
// Récupère l'image
$image = $profil->getImage();
// Récupère le fichier soumis
$file = $image->getFile();
// Crée un nom unique pour chaque image
$name = md5(uniqid()).'.'.$file->guessExtension();
// Déplace le fichier
$file->move($this->getParameter($path), $name);
// Donne le nom à l'image
$image->setName($name);
$user->setImage($name);
$profil->setUser($connectedUser);
$manager->persist($profil);
$manager->flush();
}
【问题讨论】:
-
I modify the memory_limit = -1 in php.ini, and upload_max_filesize = 200M post_max_size = 200M- 如果你做了所有这些,那么我唯一能想到的就是你的 VPS 没有足够的 RAM。 -
嗯,好的,但是有没有替代方案可以占用更少的 RAM?最大 2MB 的图片上传会占用所有 RAM,这有多奇怪?