PHP Classes

Fatal error: Allowed memory size exhausted.

Recommend this page to a friend!

      Move Me GIF  >  All threads  >  Fatal error: Allowed memory size...  >  (Un) Subscribe thread alerts  
Subject:Fatal error: Allowed memory size...
Summary:Also my ideas!
Messages:4
Author:joss daxtin
Date:2022-11-13 03:03:31
 

  1. Fatal error: Allowed memory size...   Reply   Report abuse  
Picture of joss daxtin joss daxtin - 2022-11-13 03:03:31
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 65029200 bytes) in ./php/movemegif/GifBuilder.php on line 178

I got this error while recursively calling the addFrame function for each image in a given folder (with about 230 files, ~230KB each)

...

if (file_exists($mypath)) {
$images = glob($mypath."*.png");

foreach($images as $image) {
$builder->addFrame()
->setCanvas(new FileImageCanvas($image))
->setDuration(8); }

}

...

Conversely, everything works fine while using the very same code for folders with fewer files. So it seems a problem that only occurs while handling too many files.

$extensionContents .= $graphic->getContents();
is the line (in GifBuilder.php) causing the issue.

Any suggestion?
Thanks!

  2. Re: Fatal error: Allowed memory size...   Reply   Report abuse  
Picture of Patrick Van Bergen Patrick Van Bergen - 2022-11-13 09:13:20 - In reply to message 1 from joss daxtin
Hi Joss,

Thanks for using my package. I'll try to help you out.

You describe that the problem occurs when you try to create a GIF of 230 frames from 230KB PNG files. The error says that the amount of memory assigned to the process is 256MB and that it has been exceeded.

The problem is not the amount of files, but the amount of internal memory they use. Perhaps you can increase the memory limit of the PHP process to 1GB or more (see for example https://wpastra.com/docs/increasing-php-memory-limit-website/ ).

I also want to note that there will still be a limit of what MoveMeGIF can handle. It's simply not designed for very large animated gif's, and I don't have any plans to pick it up again.

Good luck and let me know what you find.


  3. Re: Fatal error: Allowed memory size...   Reply   Report abuse  
Picture of joss daxtin joss daxtin - 2022-11-13 23:25:17 - In reply to message 2 from Patrick Van Bergen
Hi Patrick,
thank you for your prompt reply and your suggestions.

I was aware that the issue was related to the memory limit for the PHP process on my hosting, but I was wondering if there was any workaround, like scaling the frames/images to a lower quality or moving the buffer contents to file when it reaches a certain size.

I understand, tho, your intention to stop developing this package.
Thank you anyway for your kind support.

  4. Re: Fatal error: Allowed memory size...   Reply   Report abuse  
Picture of Patrick Van Bergen Patrick Van Bergen - 2022-11-14 08:15:35 - In reply to message 3 from joss daxtin
I might be able to help you out some more if you could tell me something about what it is you're trying to reach.

Is it be possible to use Javascript for your animation?

greetings,
Patrick