Forum Moderators: coopster

Message Too Old, No Replies

memory limit

         

Sandro87

12:07 am on Feb 3, 2010 (gmt 0)

10+ Year Member



Let's say we have memory_limit = 16M

I have a script that processes two 9MB-each images. If this script processes the first one and then the second one of course chronologically will the second one "overflow" the memory limit or PHP destroys and frees the memory once it has done with the first image even if the script it's still running?
What I think is that unless I need it later in the script I should destroy it in memory so it could be available for next file (?).
What if the script gets the files FROM un upload form with those 2 files? In that case the memory limit will be reached instantly?

mattclayb

8:54 am on Feb 3, 2010 (gmt 0)

10+ Year Member



The memory you require will depend on what processing and what extensions you have installed in PHP.

For example, if you are resizing a 9MB image through PHP you would need way more than 16M (probably nearer 128M using GD). If your using GD library to resize the image, PHP would need more memory to do this rather than ImageMagick.

With the upload from the form, this also depends on your upload limit and POST limits. If your using apache server and have sufficient rights, you can adjust these settings through a .htaccess file with something like -

memory_limit = 96M
post_max_size = 64M
upload_max_filesize = 64M

rocknbil

7:48 pm on Feb 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if you are resizing a 9MB image through PHP you would need way more than 16M (probably nearer 128M using GD).


To which I'll only add, the reason it does this: when you upload a 9MB image, GD creates a virtual bitmap in memory to work the image. A bitmap is uncompressed, so it takes much more than the uploaded 9MB to work it. ImageMagick 1) does it's thing in it's own process, separate from the PHP process requesting it, and 2) does a lot of it's work in virtual memory, on disk, instead of draining RAM.

Sandro87

8:13 pm on Feb 3, 2010 (gmt 0)

10+ Year Member



I actually thought it would convert to bitmap. Is there any way I could predict the memory used according to a specific file size?

rocknbil

1:31 am on Feb 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think so (any other takers?) If you have a jpg image, what compression algo is it using and how much compression ratio is applied? And thereby hangs the problem.

I am sure you could probably read the file headers to get this info and come up with a close approximation, but . . . this can only take place after it's uploaded.