473,785 Members | 2,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Allowed memory size exhausted

hi there!

i save images in a mysql db and i wrote a script called getimage.php to
display them.
in my getimage.php i want to resize my images to display them as
thumbnails but there always occurs the following error:

<b>Fatal error</b>: Allowed memory size of 188743680 bytes exhausted
(tried to allocate 240 bytes) in <b>.../public_html/getimage.php</b> on
line <b>x</b><br />

it always tries to allocate either 240 or 60 bytes.
line x equals: $image_p = imagecreatetrue color($newWidth , $newHeight);

my configuration:

PHP Version 4.3.10
Apache/2.0.49 (Linux/SuSE)
GD Version: bundled (2.0.15 compatible)
memory_limit 180M !!!!!!!!

the machine has 512MB RAM.

I tried it with a jpg:
- the size was 163kb.
- the width was 533px
- the height was 400px

it was not a really big image but it also didn't worked with smaller
ones.

my code:
include "inc/Main.inc";
$Main = new Main();
$Database = new Database();
$Database->SQLStatement = "SELECT ImgData, ImgType, ImgExt, ImgWidth,
ImgHeight FROM ProductPic WHERE ProductId=". $_REQUEST[ pid ];
$Pic = $Database->Query();
$type = $Pic[ 0 ][ ImgType ];
// set headers for image mime type
Header( "Content-type: $type");
// request thumbnail
if ( $_REQUEST[ t ] == "tmb" )
{
$newWidth = 60;
$factor = $newWidth * $Pic[ 0 ][ ImgWidth ];
$newHeight = $factor * $Pic[ 0 ][ ImgHeight ];

// resample
$image_p = imagecreatetrue color($newWidth , $newHeight);
$image = imagecreatefrom string( $Pic[ 0 ][ ImgData ] );
imagecopyresamp led($image_p, $image, 0, 0, 0, 0, $newWidth,
$newHeight, $Pic[ 0 ][ ImgWidth ], $Pic[ 0 ][ ImgHeight ]);

// output
switch ( $Pic[ 0 ][ ImgExt ] )
{
case 1:
imagegif($image _p, null, 75);
break;
case 2:
imagejpeg($imag e_p, null, 75);
break;
case 3:
imagepng($image _p, null, 75);
break;
}
}
else // request full size image
{
$data = $Pic[ 0 ][ ImgData ];
echo $data;
}

I know this problem if the memory limit is set to 8 MB but what the
hell is the solution here?

the free command on the linux-console returned:

total used free shared buffers
cached
Mem: 508588 122300 386288 0 14572
61948
-/+ buffers/cache: 45780 462808
Swap: 497972 0 497972
kind regards
flo

Feb 9 '06 #1
3 6708
d
<f.*****@rona.a t> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
hi there!

i save images in a mysql db and i wrote a script called getimage.php to
display them.
in my getimage.php i want to resize my images to display them as
thumbnails but there always occurs the following error:

<b>Fatal error</b>: Allowed memory size of 188743680 bytes exhausted
(tried to allocate 240 bytes) in <b>.../public_html/getimage.php</b> on
line <b>x</b><br />

it always tries to allocate either 240 or 60 bytes.
line x equals: $image_p = imagecreatetrue color($newWidth , $newHeight);

my configuration:

PHP Version 4.3.10
Apache/2.0.49 (Linux/SuSE)
GD Version: bundled (2.0.15 compatible)
memory_limit 180M !!!!!!!!

the machine has 512MB RAM.

I tried it with a jpg:
- the size was 163kb.
- the width was 533px
- the height was 400px

it was not a really big image but it also didn't worked with smaller
ones.

my code:
include "inc/Main.inc";
$Main = new Main();
$Database = new Database();
$Database->SQLStatement = "SELECT ImgData, ImgType, ImgExt, ImgWidth,
ImgHeight FROM ProductPic WHERE ProductId=". $_REQUEST[ pid ];
$Pic = $Database->Query();
$type = $Pic[ 0 ][ ImgType ];
// set headers for image mime type
Header( "Content-type: $type");
// request thumbnail
if ( $_REQUEST[ t ] == "tmb" )
{
$newWidth = 60;
$factor = $newWidth * $Pic[ 0 ][ ImgWidth ];
$newHeight = $factor * $Pic[ 0 ][ ImgHeight ];

// resample
$image_p = imagecreatetrue color($newWidth , $newHeight);
$image = imagecreatefrom string( $Pic[ 0 ][ ImgData ] );
imagecopyresamp led($image_p, $image, 0, 0, 0, 0, $newWidth,
$newHeight, $Pic[ 0 ][ ImgWidth ], $Pic[ 0 ][ ImgHeight ]);

// output
switch ( $Pic[ 0 ][ ImgExt ] )
{
case 1:
imagegif($image _p, null, 75);
break;
case 2:
imagejpeg($imag e_p, null, 75);
break;
case 3:
imagepng($image _p, null, 75);
break;
}
}
else // request full size image
{
$data = $Pic[ 0 ][ ImgData ];
echo $data;
}

I know this problem if the memory limit is set to 8 MB but what the
hell is the solution here?

the free command on the linux-console returned:

total used free shared buffers
cached
Mem: 508588 122300 386288 0 14572
61948
-/+ buffers/cache: 45780 462808
Swap: 497972 0 497972
kind regards
flo


Take a look at imagedestroy():

http://www.php.net/imagedestroy

You should use that on all images after you have finished using them, as it
frees the memory used by/associated with that image.

One more note - why don't you cache your thumbnails? That way you don't
have to generate them every time.

(also, purely fyi, you might want to consider putting quotes around string
keys in your arrays - PHP accepts it when you don't, but it's regarded as
bad practice to do so)
Feb 9 '06 #2
thank you... the problem was that i just turned my brain on yet ;-)

the factor i used was: $factor = $newWidth * $Pic[ 0 ][ ImgWidth ];
but i want to resize, so the factor should be this: $factor = $newWidth
/ $Pic[ 0 ][ ImgWidth ];

after debugging my $factor the newWidth and newHeight parameters for
the imagecreatetrue color command were correct!

Feb 9 '06 #3
d
<f.*****@rona.a t> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.com...
thank you... the problem was that i just turned my brain on yet ;-)

the factor i used was: $factor = $newWidth * $Pic[ 0 ][ ImgWidth ];
but i want to resize, so the factor should be this: $factor = $newWidth
/ $Pic[ 0 ][ ImgWidth ];

after debugging my $factor the newWidth and newHeight parameters for
the imagecreatetrue color command were correct!


Good work :)

Still - don't forget the imagedestroy() function, or caching your
thumbnails - they'll save you a LOT of work down the road.

dave
Feb 9 '06 #4

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

Similar topics

3
12367
by: Paul | last post by:
Hi, I'm using TikiWiki and was using its file upload feature, trying to upload a 2MB file. I get this error: Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 1677706 bytes) in /var/html/www/tiki/lib/filegals/filegallib.php on line 30 Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to
2
4692
by: Phil Powell | last post by:
Actually the client is saying it sometimes happens and sometimes doesn't happen, and when they refresh their screen it clears itself (I assume the memory clears). Here is line 1135: $result = mysql_query($this->query, $this->dbcnx) or die(@include("$DOCUMENT_ROOT${devpath}errors/query_error.php")); It is found here in this class method:
0
711
by: Joe | last post by:
Hi, Now I am using Red Hat Linux 8.0 + squirrelmail as mail server. One day, I got the following warning: Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 35 bytes) in /usr/share/squirrelmail/functions/imap_messages.php on line 325
0
2297
by: prabhjeet | last post by:
I have DB2 v9 trial version installed on Windows 2003 Server with 1GB RAM. I am able to connect remotely through an ODBC data source to the database, but when I try to connect to that data source using my application, I get the following error in db2diag.log: 2007-02-20-10.41.37.812000+330 E1562H677 LEVEL: Warning (OS) PID : 3720 TID : 2000 PROC : db2syscs.exe INSTANCE: DB2 NODE : 000 DB : TEST APPHDL : 0-63 APPID:...
1
2977
by: Kimmo Laine | last post by:
Hi! We've encountered a strange problem concerning memory usage. In the previous install the maximum memory amount per page was limited to 8 MB and it was never reached. Now, after upgrading both hardware and software, running the same scripts that used to be fine with 8 MB hit the roof all the time. The maximum memory allocation was set to 128 MB and still PHP encounters fatal errors with allowed memory size exhausted. Pardon my french,...
3
3017
by: spereira | last post by:
I am running XAMPP for Mac OS X 0.6.1 ! And since it did not have PDF libarires I downloaded ezpdf from the url:http://sourceforge.net/project/showfiles.php?group_id=45168&package_id=37830&release_id=147645 unzipped into a folder pdf_test And tried to run from the local http://localhost/pdf_test/readme.php gets the error Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 76912 bytes) in...
7
26625
by: Jim Carlock | last post by:
I'm filling a really large array. Is there a way to get by this error message without editing the php.ini? The array needs to get built once, then looped through to fill a data- base, and it will get alot bigger than 1.5MB, I'm going to guess maybe at least 100MB. <snip> PHP Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 10 bytes) in...
1
1670
by: David d'Angers | last post by:
hi group: i've been struggling with this simple problem with dismay i need all the file names in a directory since the number of files in a directory is unknown, a friend here in the group hinted me to use dynamic memory allocation: namely functions like malloc etc in the spirit of code re-use
5
24805
by: kumarmdb2 | last post by:
Hi guys, For last few days we are getting out of private memory error. We have a development environment. We tried to figure out the problem but we believe that it might be related to the OS (I am new to Windows so not sure). We are currently bouncing the instance to overcome this error. This generally happen at the end of business day only (So maybe memory might be getting used up?). We have already increased the statement heap & ...
0
9643
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
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
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
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
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
7494
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.