PHP Classes

Fatal Error

Recommend this page to a friend!

      class.upload.php  >  All threads  >  Fatal Error  >  (Un) Subscribe thread alerts  
Subject:Fatal Error
Summary:Run out of memory, fatal error
Messages:2
Author:Kevin Richard
Date:2008-02-14 08:54:45
Update:2008-02-15 15:23:30
 

  1. Fatal Error   Reply   Report abuse  
Picture of Kevin Richard Kevin Richard - 2008-02-14 08:54:45
When running this script I get the following error:

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 2320 bytes) in /.../.../class.upload.php on line 2395

Here is the script I am trying to run. The filenames are gathered from a database. I have to upload and process in two steps, because I'm using an ActiveX interface for uploading. Any help would be greatly appreciated.
Thanks

...
[Select photoID from database]
while ($row = mysql_fetch_array($result)) {
$handle = new Upload("to_be_processed/".$row['photoID'].".jpg");
if ($handle->uploaded) {
$handle->image_resize = true;
$handle->image_ratio = true;
$handle->image_y = 580;
$handle->image_x = 580;
$handle->Process('./photos/');
if ($handle->processed) {
$handle->image_resize = true;
$handle->image_ratio = true;
$handle->image_y = 125;
$handle->image_x = 125;
$handle->Process('./thumbs/');
if ($handle->processed) {
@unlink("to_be_processed/".$row['photoID'].".jpg");
} else {
$error = 1;
echo '<br>Thumbnail not created. Process not completed.';
echo ' Error: ' . $handle->error;
}
} else {
$error = 1;
echo '<br>Photo not resized. Process not completed.';
echo ' Error: ' . $handle->error;
}
} else {
$error = 1;
echo '<br>Requested file not found. Process not completed.';
echo ' Error: ' . $handle->error;
}
$handle->Clean();
}

  2. Re: Fatal Error   Reply   Report abuse  
Picture of Murray Nich Murray Nich - 2008-02-15 15:23:30 - In reply to message 1 from Kevin Richard
This is an error from the GD library. Processing the image has used more memory than is availabe to the php script.

The GD library is very heavy on memory usage when processing large images.
Its not the size of the picture in Kb that counts its the PIXEL count ie 2000px*2000px etc.

If you do not have direct access to php.ini on the server to change the default 8Mb memory limit to something else, you can try using ini_set("memory_limit","32M"); at the top of your script. change 32 to whatever your images require or your server will allow(there can be other scripts restricting memory use on to applications on the server).

Im no expert at this stuff but I have been working with a cropping application built to crop large images with the Gd library, proving quite a challenge with GD.

I couldnt find any definative calculations for working out how much memory would be used by the server, a few ideas but no exact answers that seemed to corilate with the erros I was getting, so if anyone has one please yell out.