php script memory leak?
Posted: Wed Nov 17, 2004 3:48 am
I have the same script running on 2 servers from the same provider, with supposedly the exact same setup, however, one works, and the other (on the production server - typical) gives me a memory error...
Here's my code...
The touble is, I think 8Mb is enough to be running this script, can anyone see where i'm using all that memory?? Each of the pics i'm re-processing is about 750K, but that wouldn't make any difference to the script would it??Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 6400 bytes) in /home/fhlinux197/r/roobottom.com/user/htdocs/photos.php on line 24
Here's my code...
Code: Select all
//process pic function-----------------------------------------------------------------
$new_width=100; //Image width Change if needed
$new_height=100; //Image height Change if needed
//JPEG function
function thumb_jpeg($image_name, $subFolder)
{
global $new_width;
global $new_height;
global $global_photoRoot;
if(file_exists($global_photoRoot.$subFolder."th_".$image_name)) {
//the file already exists
} else {
//resize but constrain proportions...
list($width_orig, $height_orig) = getimagesize($global_photoRoot.$subFolder.$image_name);
if ($width && ($width_orig < $height_orig)) {
$new_width = ($new_height / $height_orig) * $width_orig;
} else {
$new_height = ($new_width / $width_orig) * $height_orig;
}
$destimg=imagecreatetruecolor($new_width,$new_height) or die("Cannont create GD2 image");
$srcimg=ImageCreateFromJPEG($global_photoRoot.$subFolder.$image_name) or die("Problem In opening Source Image");
imagecopyresized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,$width_orig,$height_orig) or die("Problem In resizing");
ImageJPEG($destimg,$global_photoRoot.$subFolder."th_".$image_name) or die("Problem In saving");
}
}
//--------------------------------------------------------------------------------Thank You in advance.The error message relates to line 24 of the above formatting.