memory_limit doesn't affect imagecreatetruecolor?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dbevfat
Forum Contributor
Posts: 126
Joined: Tue Jun 28, 2005 2:47 pm
Location: Ljubljana, Slovenia

memory_limit doesn't affect imagecreatetruecolor?

Post by dbevfat »

I was playing around and tried to allocate an extremely large image with imagecreatetruecolor(10000, 10000) to deliberately hit the memory limit on my server (8MB).

When I ran the script, it started consuming memory, then the script stalled, returned nothing, and the memory was freed. No "memory limit hit" message from PHP though, and memory usage of the script reached over 1GB (the script alone, not total memory usage on my system).

Does this mean that imagecreatetruecolor() doesn't obey the memory limit, or did I just miss something?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

hmm.... it seems so. what does return memory_get_peak_usage()? (you may need recent version of php to use this function).
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

1K x 1K true color image is 4MB.
User avatar
dbevfat
Forum Contributor
Posts: 126
Joined: Tue Jun 28, 2005 2:47 pm
Location: Ljubljana, Slovenia

Post by dbevfat »

Weirdan wrote:hmm.... it seems so. what does return memory_get_peak_usage()? (you may need recent version of php to use this function).
Will try, but I have WindowsXP at home, and I know some memory-related functions are not supported on Windows.
feyd wrote:1K x 1K true color image is 4MB.
True, and a 100x100 image is probably about 40KB. But a 10000x10000 image is 400MB (in theory) and over 1GB in practice.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

oops, I thought I saw 1000, not 10,000 in your post.
User avatar
dbevfat
Forum Contributor
Posts: 126
Joined: Tue Jun 28, 2005 2:47 pm
Location: Ljubljana, Slovenia

Post by dbevfat »

feyd wrote:oops, I thought I saw 1000, not 10,000 in your post.
Happens, with all those 0's ... :)
Weirdan wrote:hmm.... it seems so. what does return memory_get_peak_usage()? (you may need recent version of php to use this function).
That function doesn't exist on PHP 5.1.6, which is the latest stable windows version. I'll try my gentoo server tomorrow.

Thanks
Post Reply