3

I have a Symfony 4 application where I upload files with a 2MB restriction, this restriction works, in a dev environment all works perfectly, the image is well uploaded, but in prod, I always have the same message :

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

 

this line is the problem

$file->move($this->getParameter($path), $name);

it moves the image in my assets so that I recover it in the view, I modify the memory_limit = -1 in php.ini, and upload_max_filesize = 200M   post_max_size = 200M

but still the same problem the image does not upload because of that, do you have a solution?

I specify that all this is on a VPS

UPDATE:

here is the code that is problematic in production

 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();

    }
  • 1
    `I modify the memory_limit = -1 in php.ini, and upload_max_filesize = 200M post_max_size = 200M` - If you did all of that then the only thing that I can think of is that your VPS doesn't have enough RAM. – Leon Kunštek Jan 08 '20 at 22:49
  • 1
    This might help you: https://www.drupal.org/forum/support/post-installation/2013-02-12/solved-fatal-error-allowed-memory-size-of-33554432-bytes. – Leon Kunštek Jan 08 '20 at 22:51
  • 1
    hmm okay, but is there an alternative that would take less RAM? How strange is it that a maximum 2MB image upload uses all the RAM? – Eclip tique Jan 08 '20 at 22:52

1 Answers1

2

Try print phpinfo and check that these variables are actually updated or not. Also it might be your path issue or code error. Try check the permissions of the folder as well . It always does not seems to be a memory issue . You can check here that it can be you coding style , your query or any other scenario which is causing this issue Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)

Amit Sharma
  • 1,775
  • 3
  • 11
  • 20