473,799 Members | 3,006 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($filen ame,0,2);
$srcsize = getimagesize($d ir."/".$filename );
switch($srcsize['mime'])
{
case "image/jpeg":
$src_img = imagecreatefrom jpeg($dir."/".
$filename);
break;
case "image/png":
$src_img = imagecreatefrom png($dir."/".
$filename);
break;
case "image/gif":
$src_img = imagecreatefrom gif($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 = imagecreatetrue color($dest_w, $dest_h);
imagecopyresamp led($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_i mg);
break;
case "image/gif":
header("content-type: image/gif");
imagegif($dst_i mg);
break;
}

// Destroy images
imagedestroy($s rc_img);
imagedestroy($d st_img);
}

Apr 5 '08 #1
2 2216
*** 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
14170
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 Smarty-2.6.7.tar.gz on a system running WindowsXP SP2. Apache and PHP tested out fine. After adding Smarty, I ran the following http://localhost/testphp.php
0
3294
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 Authentication. I have a security constraint restricting access to the application so that when I attempt to access the app I am redirected to the login page. This works as expected both when accessing the application via the Apache proxy or hitting...
1
2439
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 remote debugging (this is displayed on the console).' 'Start the Java debugger:' 'jdb -host your_host -password the_password' 'You should be able to debug your Java classes now using the jdb
0
2033
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 that we're seeing is that we can type: http://foo.com but the url that gets displayed is
3
3223
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 to configure them on my computer. Can somebody help me - this is what I have done so far. Installed Apache 2.0, it worked perfectly ( I checked with my browser - http://localhost) till the point where I started to point where I
8
6307
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 Apache directory - unable to find httpd.h under /usr/local/apache/include So then I run this command: find / -name httpd.h
2
1679
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 48% of a xeon 3.0 processor!!! <IfModule prefork.c> StartServers 8 MinSpareServers 5 MaxSpareServers 20
3
17129
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 the service using client stub, I get this error... Exception in thread "main" java.lang.Error: Unresolved compilation problems: org.apache cannot be resolved to a type org.apache cannot be resolved to a type org.apache cannot be resolved to a...
2
1475
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 updates are already in the db, and the code I have is currently a mess so I decided to try using array_diff to find the new vs. old shows. Getting the list of updates into an array is no problem, but getting the list of shows from my db into array...
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10491
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10268
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9079
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.