ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Fatal error: Allowed memory size of 33554432 bytes

August 14, 2007 7:36am

Subscribe [1]
  • #1 / Aug 14, 2007 7:36am

    Eskills

    4 posts

    Hi guys,

    I’ve created a thumbnail plug-in and i am getting this error…
    “Fatal error: Allowed memory size of 33554432 bytes…” I managed to fix it with this statement

    ini_set("memory_limit","12M");

    but now I’m getting it again… does anyone have an idea what causes it and the permanent remedy…

    Thanks

  • #2 / Aug 14, 2007 5:40pm

    gungbao

    70 posts

    Hi Eskills,

    it says your script consumes more memory as you allow php to use for each started php-process.

    Unfortunately, you did not tell more about your hosting-ressources… but

    if ini_set(“memory_limit”,“12M”);

    did work for you, try to set it to 20M - but keep in mind this is given to any single started php-process, so you will run in an unscalable application depending on your total ram and your num of visitors (if your thumbnail-generator is available from public).

    if you have no unlimited ressources of ram 😊 do better php-code 😊

    keep also in mind unset() does free ram but does start “slow” php garbage-cleanup…

    if all does not help, let us know - there are some dump stupid receipes to resolve.

  • #3 / Aug 14, 2007 6:57pm

    Derek Jones

    7561 posts

    Just an FYI that the error message indicates that the limit is already set to 32MB, so you would need to increase it above that, assuming that the high memory usage is warranted.

  • #4 / Aug 15, 2007 3:19am

    Eskills

    4 posts

    It seems to work when whenever i extend the memory… but this looks like a problem cause i can’t keep extending the memory…. i noticed that it only happens when i upload large images….

    I am currently working on wamp on localhost

    <?php if (!defined(‘BASEPATH’)) exit(‘No direct script access allowed’);
    /**
      *
      *
    *  @author     Edmond Sebetseba
    *  @since     Version 0.1
    *  @purpose         generate thumbnails.
    *  @website         http://www.mellocube.com/
    */

    /*
    Instructions:

    Load the plugin using:

        $this->load->plugin(‘createthumb’);

    once loaded, you can call  

    createThumb($source_file,$destnation_file);

    */

    ini_set(“memory_limit”,“12M”);

    function createThumb($source,$dest) {

    $thumbnail_size = 100;
    $size = getimagesize($source);
    $width = $size[0];
    $height = $size[1];

    //image extension
    $ext = strtolower(end(explode('.', $source)));


    if($width > $height) {
    $x = ceil(($width - $height) / 2 );
    $y = NULL;
    $width = $height;
    } elseif($height > $width) {
    $y = ceil(($height - $width) / 2);
    $x = NULL;
    $height = $width;
    }

      $new_img = ImageCreatetruecolor($thumbnail_size,$thumbnail_size);
     
      if ($ext==‘jpg’)
      {
    $img = imagecreatefromjpeg($source);
    imagecopyresampled($new_img,$img,0,0,$x,$y,$thumbnail_size,$thumbnail_size,$width,$height);
    imagejpeg($new_img,$dest,100);
    }
      if ($ext==‘gif’)
      {
    $img = imagecreatefromgif($source);
    imagecopyresampled($new_img,$img,0,0,$x,$y,$thumbnail_size,$thumbnail_size,$width,$height);
    imagegif($new_img,$dest,100);
    }
     
      if ($ext==‘png’)
      {
    $img = imagecreatefrompng($source);
    imagecopyresampled($new_img,$img,0,0,$x,$y,$thumbnail_size,$thumbnail_size,$width,$height);
    imagepng($new_img,$dest,100);
    }
         
     
    }

    ?>

  • #5 / Aug 15, 2007 4:23am

    rogierb

    697 posts

    Large memory usage is a know problem with images, especially JPGs.
    JPsG are compressed images wich will be ‘unpacked’ then processed and ‘re-packed’. This ‘unpacking’ uses a lot of memory, sometimes in excess of 100 times the size of the image.

    Nothing to do about that, although newer image libraries do use less memory.

    Maybe someone found a solution, I sure would like to know. Got one server which has 512M as a memory limit…

  • #6 / Aug 15, 2007 8:14am

    gungbao

    70 posts

    aha - I initially thought you run in ram limits coz of batch processing.

    Have you tried a syscall to ImageMagick

    try

    http://www.imagemagick.org/script/mogrify.php

    and pls. let us know results.

    Greetings
    Chris

  • #7 / Mar 13, 2009 8:53am

    Stu Green

    84 posts

    Hi I’m just bringing this back to light because it’s happening for me when using the Image class.

    Fatal error: Allowed memory size of 12582912 bytes exhausted (tried to allocate 2304 bytes) in ***/system/libraries/Image_lib.php on line 1157

    One member said ‘use better code’ but this is the CI image class we are talking about here - no mods.

    I’m resizing images and creating thumbnails yes, but the image is only 320kb.

    Any thoughts, or has this topic been updated recently elsewhere? (I just did a Google search).

    Thanks

  • #8 / Mar 13, 2009 10:15am

    pistolPete

    1071 posts

    I’m resizing images and creating thumbnails yes, but the image is only 320kb.

    The image file size doesn’t matter, it’s the image resolution which determines the memory use.
    How many pixels is the resolution of this image?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases