473,396 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Apache Eating up ram using imagecreatefrom

I have a picture site. I save the original and a thumbnail of every
picture. Now if they click on a thumbnail then they go to the
viewer page where they then see an intermediate picture. I have php
opening the original and resizing it and sending the resized image
out. It works great and not much load. Better than having 1.7
million more pics. Problem I am having is that after a few hours
apache is like 700 megs in memory and will start messing up. Is
there a memory leak in this function or something where it cannot
unload the memory used from the pics? Here is my resize image code
that I have so far.

if(isset($_GET['image']))
{
$filename = $_GET['image'];
$dir = "pics/".substr($filename,0,2);
$srcsize = getimagesize($dir."/".$filename);
switch($srcsize['mime'])
{
case "image/jpeg":
$src_img = imagecreatefromjpeg($dir."/".
$filename);
break;
case "image/png":
$src_img = imagecreatefrompng($dir."/".
$filename);
break;
case "image/gif":
$src_img = imagecreatefromgif($dir."/".
$filename);
break;
}
if($srcsize[0] $srcsize[1])
{
$dest_w = 420;
$dest_h = (420 / $srcsize[0]) * $srcsize[1];
}else{
$dest_w = (420 / $srcsize[1]) * $srcsize[0];
$dest_h = 420;
}
//echo $dest_w."--".$dest_h."--".$srcsize[1]."--".$srcsize
[0];
$dst_img = imagecreatetruecolor($dest_w, $dest_h);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_w,
$dest_h, $srcsize[0], $srcsize[1]);
switch($srcsize['mime'])
{
case "image/jpeg":
header("content-type: image/jpeg");
imagejpeg($dst_img);
break;
case "image/png":
header("content-type: image/png");
imagepng($dst_img);
break;
case "image/gif":
header("content-type: image/gif");
imagegif($dst_img);
break;
}

// Destroy images
imagedestroy($src_img);
imagedestroy($dst_img);
}

Apr 5 '08 #1
2 2196
*** Extremest escribió/wrote (Fri, 04 Apr 2008 22:18:32 -0500):
I have a picture site. I save the original and a thumbnail of every
picture. Now if they click on a thumbnail then they go to the
viewer page where they then see an intermediate picture. I have php
opening the original and resizing it and sending the resized image
out. It works great and not much load. Better than having 1.7
million more pics. Problem I am having is that after a few hours
apache is like 700 megs in memory and will start messing up. Is
there a memory leak in this function or something where it cannot
unload the memory used from the pics?
I can't tell you about memory leaks (though it seems there are some), but
resizing images is quite an intensive task and there's no need to do it
*every time* the image is requested. I'd suggest the following algorithm:

Keep two directories: pics for original pictures and thumbs for thumbnails
When a pic is requested, check whether there's a thumbnail already; you can
also use filemetime() to check if its updated
If thumb exist, send it. If not, generate it into disk and send it.

Alternatively, in the future you can simplify this generating the thumbnail
when the image is uploaded (though, given the number of pics, I suppose
they come from a DVD or something like that).

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor en cubitos: http://www.demogracia.com
--
Apr 5 '08 #2
The pics that are being generated are 420x420 with respect to ratio.
I don't have the space to save them. Big thing is that apache or
php one of them should be freeing this memory back up at the end but
it's not. I guess it's php since when I added that page is when I
started having the problems a couple days later. So I guess I'll
create a php bug.

Apr 5 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
0
by: Kevin Sagon | last post by:
I am running a J2EE Web App under Tomcat 4.1 with Apache 2.0 proxying requests. Everything is configured and working appropriately however I ran into a problem after configuring J2EE Form...
1
by: Peter Chatterton | last post by:
I want to use jdb for debugging a servlet. I'm using Apache/JServ with jdk 1.4 (via Textpad on win2K SP 3). The 'gospel' I'm using is: 'Start the server manually and record the password for...
0
by: bruce | last post by:
Hi... Update.... We have the following setup in our httpd.conf file. We've tried to give what's related to the issue. We're trying to set up a virtual host for a test project. The behavior...
3
by: genenamg | last post by:
Hi, I am trying to run and configure Apache 2.0, php 5 and mysql on win xp professional - this is the first time I have tried to install and configure all three. I am having difficulty trying...
8
by: lawrence k | last post by:
I've installed Apache 1.3.36 on my Redhat EL 3 machine. Now I'm trying to install PHP 5.1.4. I can not get the ./configure command to work. I keep getting this error: configure: error: Invalid...
2
by: gavino | last post by:
REHDAT LINUX 4S PHP 4.3.9 LEGACY APP I MOVED NOW EATS MEMORY CAN ANYONE TAE A LOOK ? I FIXED ONE PARTIALLY BY CHANGING TO here are my apache settings: 1 page laoding for a few seconds eat like...
3
by: amanjsingh | last post by:
Hi, I am trying to implement Java Web Service using Apache Axis2 and Eclipse as a tool. I have created the basic code and deployed the service using various eclipse plugin but when I try to invoke...
2
by: pedalpete | last post by:
Hi Gang, I've run into a serious problem, and can't seem to find the issue in my somewhat simple code. I've got a database and I update it with concert listings. I need to check if the new...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.