ID: 42356 Updated by: [EMAIL PROTECTED] Reported By: myteamz at rogers dot com Status: Bogus Bug Type: Reproducible crash Operating System: Windows XP SP2 PHP Version: 5.2.3 Assigned To: pajoye New Comment:
"When I change my call to use imagecreatetruecolor instead of imagecreate, the memory usage is exactly the same, suggesting the PHP imagecreate is calling the GD gdImageCreateTrueColor and reducing the available image size by a factor of 4. If this is the case, why?" That's not the case. You consider the values returned by the memory info functions are accurate, they are not. "This implies that the default max image GD can handle (for height of 1024) is about 32M/1024/4 = 8K." Completely wrong, you are looking at the wrong place to fix your problem. If you have doubt about the cause (memory limit), try to run your script (and only what you show here) using CLI (command line). Previous Comments: ------------------------------------------------------------------------ [2007-08-21 15:25:35] myteamz at rogers dot com With understanding of how much memory GD uses per pixel (4 bytes), I am able to scale image request size to fit in memory, but result is that image is not large enough to build tree. When increasing memory_limit to 128M, I still run into 32M limit, and upon looking further, it appears that default Apache Windows distro is built with MAX_PROCESS_SIZE = 32M. This implies that the default max image GD can handle (for height of 1024) is about 32M/1024/4 = 8K. When looking further into GD documentation, there is a reason why I am using imagecreate instead of imagecreatetruecolor. The GD docs say gdImageCreate(sx, sy) has a 256 color limit, or 1 byte per pixel, while gdImageCreateTrueColor(sx, sy) has "an essentially unlimited number of colors" - presumably 32 bit or 4 bytes per pixel. When I change my call to use imagecreatetruecolor instead of imagecreate, the memory usage is exactly the same, suggesting the PHP imagecreate is calling the GD gdImageCreateTrueColor and reducing the available image size by a factor of 4. If this is the case, why? ------------------------------------------------------------------------ [2007-08-21 14:31:11] [EMAIL PROTECTED] Your image takes 13770*990*4 bytes, which is ca. 54mb. That doesn't fit in 32 mb memory limit. ------------------------------------------------------------------------ [2007-08-21 14:21:14] myteamz at rogers dot com You have ignored the other submitted info that shows (via call to memory_get_usage(true)) that the memory in use is actually less than 7M. Either the function call is reporting incorrect values, or there is a problem in the memory manager believing 32M is in use. I have subsequently added a call to memory_get_peak_usage(true), and it reports the same value as memory_get_usage(true), indicating I have come nowhere near using 32M. ------------------------------------------------------------------------ [2007-08-21 05:48:22] [EMAIL PROTECTED] "Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 13770 bytes) in C:\Program Files\Apache Software" I'm sorry but it has nothing to do with GD. imagecreate tries to allocate the memory it needs for an image but your application seems to have already used most of the available limit (32M in this case). By the way, fatal errors are not crashes or do you have a real crash? (segfault). If yes post a comment I will reopen this bug and move it to the engine category. ------------------------------------------------------------------------ [2007-08-21 01:28:22] myteamz at rogers dot com Description: ------------ I am creating a script to produce a PNG image of a chart showing common ancestors of several individuals, using the gd functionality supplied with php. After processing the input, including many calls to MySQL (version 5.0.2) all running on Apache 2.2 on Windows XP SP2, I am trying to allocate the image resource. This works for very small trees, but fails on all calls with large trees. The PHP error message is: Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 13770 bytes) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\GenChart\drawgraph.php on line 116 The offending code is: $im = imagecreate ($xsize, $ysize); Reproduce code: --------------- Lots of memory allocation/freeing is occurring in the script prior to this call. I have included several debug lines prior to the offending call, as below: $memMax = ini_get("memory_limit"); $memUsed = memory_get_usage(true); $xMax = round(30000000-intval($memUsed/$ysize),-3); $xsize = min($xMax,max($xsize,4000)); dumpData("have used $memUsed of $memMax memory"); dumpData("trying to create image of size ($xsize,$ysize)"); $im = imagecreate ($xsize, $ysize); The output, on crash, is have used 6815744 of 32M memory trying to create image of size (13770,990) Expected result: ---------------- I have changed the script to produce standard HTML output for debugging purposes, which allows me to get this info. When running as intended, with a small tree/image, the script should and does run successfully, creating an image, and returning it as a .PNG image. Running the same debug code for a small image (with no crash), the output is: have used 6553600 of 32M memory trying to create image of size (4000,690) Actual result: -------------- When running in debug mode for a large tree/image, the debug output is: have used 6815744 of 32M memory trying to create image of size (13770,990) When running as intended, the script fails and no image is returned to the browser. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42356&edit=1