Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Memory exhausted

Any ideas why I'm getting ....

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to

allocate 9792 bytes) in /home/frich/public_html/creation/systemc/sMain/upload_image.php on line 77

on the following line

$oldImage = imagecreatefromjpeg($img);

The php grabs an image from a HTML form and resizes it.

Works perfectly fine if its a small file. I.e. a few hundred KB

Tried with a larger file as I want a max of up to 4mb. The image I get an error with is ca. 2mb

Thanks in advance

like image 209
Stevanicus Avatar asked Aug 20 '10 19:08

Stevanicus


2 Answers

You are getting error

""""""""""""""""""""""""
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to

allocate 9792 bytes) in /home/frich/public_html/creation/systemc/sMain/upload_image.php on line 77
""""""""""""""""""""""""

It shows that either you are using a shared hosting because your server memory_limit is 32 MB

You need to increase your memory limit as said above by "Pekka" and "MartyIX"

but how you do this there are three ways of doing so.

1st. ask your hosting company to increase your memory limit,

they will increase it upto 48MB max that is the restriction of any hosting company for sheared hosting acount.

2nd. upload a php.ini file

with written "memory_limit = 100M and max_memory = 100M"

you can change 100M to any size that you want but that can be in limit so that it will not use extra resources of server else your account may be suspended by your hosting company

LIMITATION: this option may not work properly on every hosting because some times this code may be blocked by admin so that server resources may be consumed in LIMIT.

3rd upload a ".htaccess"

written inside it "php_value memory_limit 32M"

or

by default it is available in your hosting web directory then you can first download it as it is having other settings too. download it open it with notepad and write "php_value memory_limit 32M"

and

4th option add a PHP code your page

"ini_set('memory_limit', '32M');" (Not tested yet by me, may it work fine)

Thanks and Regards........

like image 147
Shailender Ahuja Avatar answered Oct 02 '22 17:10

Shailender Ahuja


The image you are trying to process is too large for the 32 MB memory limit your script has.

Resizing an image takes up at least

(width in pixels) x (height in pixels) x 3 (or 4)

bytes (1 byte each for Red / Green / Blue, possible one additional byte for transparency)

You need to increase the memory_limit setting on the server, or ask the administrator to do so.

32MB is a pretty decent and common value, though - you may be out of luck if you're on shared hosting.

Alternatively, if possible on your server, use ImageMagick, whose memory consumption does not count toward the memory_limit.

like image 40
Pekka Avatar answered Oct 02 '22 16:10

Pekka