Memory Issues

See all posts Reply

Memory Issues new!
by Steve, 11 years, 10 months ago
I am using the setup described here (class.upload, uploadify and AD Gallery) on a VPS which currently has a memory_limit of 128MB. Actually the VPS only has 128MB of memory in total so this isn't really a practical limit, but basically the server has as much memory as I can give it.

I have had success uploading smaller files, but anything over about 2MB seems to fail. I have read the discussions on memory on the forum and thought that was the issue, but I did some further investigations, and I am able to upload some files of 4320 x 3240 pixels (jpg below 2MB) but not others of the same resolution. The forum strongly suggests that memory used is determined by the dimensions of the image.

I also added a call to memory_get_peak_usage in the script, and when it works with the smaller images I get a value of 2276332 however big the jpg is (the dimensions are the same).

Is there something else I should be looking at - it seems strange to me that I can upload some images of the same pixel size correctly, but not all, and also that the memory usage of 2276332 bytes seems quite low and there is scope to process larger files.

Here is my script:

include('class.upload.php');
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile =  utf8_decode(str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']);

$file_id = md5($_FILES["Filedata"]["tmp_name"] + rand()*100000 + time());
$handle = new Upload($_FILES['Filedata']);
  if ($handle->uploaded) {
    $handle->file_src_name_body      = time().$file_id; // hard name
    //$handle->file_overwrite = true;
    //$handle->file_auto_rename = false;

    // save original file
    $handle->image_resize            = true;
    $handle->image_ratio_y           = true;
    $handle->image_x                 = $handle->image_src_x; //size of picture
    $handle->file_max_size = '5120000';
    $handle->Process($targetPath.'/'.'fullsize/');
    if ($handle->processed) {
      file_put_contents("/home/stevo/log/gallery.log","OK \n",FILE_APPEND);
    } else {
      file_put_contents("/home/stevo/log/gallery.log",$handle->error . "\n",FILE_APPEND);
    } 
    // get smaller files
    $handle->image_resize            = true;
    $handle->image_ratio_y           = true;
    $handle->image_x                 = 600; //size of picture
    $handle->file_max_size = '5120000'; // max size
    $handle->Process($targetPath.'/');

    //thumbnail creation:
    $handle->file_src_name_body      = time().$file_id; // hard name
    //$handle->file_overwrite = true;
    //$handle->file_auto_rename = false;
    $handle->image_resize            = true;
    //$handle->image_ratio_y           = true;
    $handle->image_ratio_x           = true;

    //thumbnail creation:
    $handle->file_src_name_body      = time().$file_id; // hard name
    //$handle->file_overwrite = true;
    //$handle->file_auto_rename = false;
    $handle->image_resize            = true;
    //$handle->image_ratio_y           = true;
    $handle->image_ratio_x           = true;
    $handle->image_y                 = 70; //size of picture
    $handle->file_max_size = '5120000'; // max size
    $handle->Process($targetPath.'/'.'thumbs/');

    file_put_contents("/home/stevo/log/gallery.log",memory_get_peak_usage()."\n",FILE_APPEND);
    file_put_contents("/home/stevo/log/gallery.log",$handle->log . "\n", FILE_APPEND);
    $handle-> Clean();
    echo "1";
  } else {
  }
}
Reply
Re: Memory Issues new!
by colin, 11 years, 10 months ago
First, check the the web server's log, it will tell you why the process crashes, and will indicate whether it is due to memory running out.

It is true that the pixels count is important for the memory. But also the colour space, transparency, etc... It is quite hard to measure the memory used by GD, and I am not sure memory_get_peak_usage includes it.Reply
Re: Memory Issues new!
by Steve, 11 years, 10 months ago
It wasn't actually crashing. What was happening was I hadn't set my upload_max_filesize high enough. Thanks for the help.Reply