1

Hi I am having an error Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 21944 bytes) when trying to use imagecreatefromstring

        $imageFile = imagecreatefromstring($image);
        if ($imageFile !== false) {
            $width = ImageSX($imageFile);
            $height = ImageSY($imageFile);
        }
        if ($this->isExifInstalled) {
            @$type = exif_imagetype($source);
            $mime = image_type_to_mime_type($type);
        }
        if ($mime === "application/octet-stream") {
            $mime = $this->image_file_type_from_binary($image);
        }
        if ($mime === "application/octet-stream") {
            $mime = $this->getMimeTypeFromUrl($source);
        }
        imagedestroy($imageFile);
Kiel
  • 483
  • 3
  • 5
  • 18
  • try increasing your memory_limit. Maybe it doesn't leak, there really is just so much memory needed. – bwoebi May 15 '14 at 12:04
  • I don't think it would be a good idea to exceed the 128MB memory. hmm but that would be my last resort. I also tried 256MB and still i still got the error but with increased allowed memory size though... – Kiel May 15 '14 at 12:07
  • well. Try setting it once to e.g. 2G (just to test), and when it the still is exceeded, there's either a memory leak in your application (you're storing somewhere the images in RAM) or there's a bug in PHP ext/gd – bwoebi May 15 '14 at 12:10
  • well i tried upgrading my memory limit to 512MB it now works but is this really necessary? or are there anything i could do to make this running without increasing the memory? – Kiel May 15 '14 at 12:18
  • Depending on how big the images are, it's necessary. You can't assume either that these functions are supposed to use as less as possible memory. – bwoebi May 15 '14 at 12:21
  • strange for me too, memory allocate is less then the available memory for this function, not sure what is going on :( – justnajm Mar 26 '21 at 23:28

1 Answers1

0

Extending the memory limit from available to double did the job, but the problem seems to be with the method "imagecreatefromstring" there must be an issue causing exhaust or false error.

can modify php.ini "memory_limit" or use ini_set("memory_limit","512M");

ini_set is preferable as using that you can identify the memory usage in future, better explore the reason how can the code be optimized without unnecessarily exceeding the limit.

danronmoon
  • 3,814
  • 5
  • 34
  • 56
justnajm
  • 4,422
  • 6
  • 36
  • 56