Forum Moderators: coopster

Message Too Old, No Replies

imagecreatefromjpg¦gif¦png allowed memory size exhausted

Know the cases and solutions, looking for suggestions

         

rocknbil

8:03 pm on Feb 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Apache/2.0.52 (CentOS)
PHP Version 4.3.9
GD bundled 2.0.28 compatible

values altered via .htaccess:
max_input_time 300 (master 60)
memory_limit 64M (master 32M)
post_max_size 20M (master 8M)
upload_max_filesize 10M (master 2M)

This client wanted to increase max file uploads to 10M, the above values had worked but one tester was getting a white screen at imagecreatefromjpg() (or gif, or png) when the programming resizes the images.

I understand the why. I upped the memory limit and that has solved it for now, but this seems to be an excessive and sloppy use of memory.

The question: is there anything we can do to optimize the image resizing using the GD toolkit? I know about ImageMagick and use it often in perl; I would rather not recompile PHP, but if we must, we must. We should probably upgrade PHP anyway.

Using an aggressive internal logging combined with memory_get_usage() to measure things throughout program execution, it averages under 50K with a few spikes to a few hundred K all except in image resizing.

Corollary, but not as important: I'm not real comfortable with the above, futzing around with PHP's defaults (there is a reason for these, and I've found some of them via the GD toolkit.) I've explored the ftp methods and can't seem to locate a viable method to use FTP for a web-based upload interface. That too, seems like a better solution but you need an ftp client to FTP from . . . got suggestions?

eelixduppy

10:57 pm on Feb 3, 2009 (gmt 0)



If your code is fully optimized (not wasting memory where you shouldn't be) then without changing your method completely then I don't see a way or using up less memory here. A 10MB image is a pretty large image to be uploading in the first place. I'd say around 4MB is probably where you want your limit to be as far as images.

rocknbil

2:03 am on Feb 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Agreed, but look at it from the client view: they are seeing ordinary users upload images directly from their cameras. imagecreatefromjpg() takes a compressed jpg and converts it to a bitmap in memory, which will often far overrun the compressed size . . . FTP is the recommended method, but couldn't locate a way to do this from a web based upload.

coopster

8:54 pm on Feb 4, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I agree with eelixduppy. Increasing the default values is OK, especially if you have a server that is quite capable.

I understand the why.

Then these won't help much, but for other readers it may come in handy ...

More PHP image upload problems [webmasterworld.com]
Uploading big images turn to black! [webmasterworld.com]

FTP is the recommended method

Recommended by ... ? If you aren't opposed to opening that door to your client than I suppose you could have them download a copy of FileZilla and open an FTP port for them. Personally, I wouldn't, but that's me. Not unless they are using secure FTP. Even so, you are then opening that port on your server to be poked at all day long. So do you then give them a VPN tunnel? I don't like any of those options myself. I would stick to secure login and file upload via http.

rocknbil

12:09 am on Feb 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Recommended by ... ?

<blushes> Ten or twelve search results, message boards, articles, to the effect that if you exceed the PHP defaults, you should be using ftp methods instead of stock file upload methods.

I read those two threads, hadn't found them before, thank you . . . however it reiterates a lot of the info I'd already found (i.e., GD toolkit can be a memory hog with larger images.)

I agree w. both, just limit the file sizes and be done with it . . . but one of the client requirements in the revision was to up the maximum upload size.

All in all, it looks like I'm off to get my admin to upgrade PHP and recompile it with ImageMagick support, which (to my understanding) spawns the image manipulation in a separate process and uses a lot less memory.