Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

Upper memory limit for PHP/Apache

I'm getting the error when I run my PHP script....

Fatal error: Out of memory (allocated 1827405824) (tried to allocate 88800 bytes)

I've added this line to my PHP script..

ini_set("memory_limit","3000M");

This statement does seem to correctly control the memory usage, but I dont seem to be able to get it above about 1.8GB. Its as if the upper memory limit is being restricted somewhere else. I've also added to the php.ini...

memory_limit = 3000M

Does anyone know if the memory is restricted elsewhere?

I'm running a local server with Xampp. I have Windows 7, 64-bit with 4GB RAM. My script uses PHP's GD image library and I get the error when trying to allocate an image reference with ImageCreateTrueColor().

(I know this is a huge amount of memory - but this is just a one-of script, and its just a lot easier to do it this way.)

Thanks.

Update....

@elusive @Orbling I expect everybody's bored whith this question, but here is the simplified code which illustrates the problem.

<?php
    ini_set("memory_limit","4000000000");
    echo "ini_get = " . ini_get('memory_limit') . "<br>
";
    echo "memory_get_usage = " . memory_get_usage(true) . "<br>
";
    $bigImageHandle = imagecreatetruecolor(22200, 24800);  //this is line 5
?>

Browser output...

ini_get = 4000000000
memory_get_usage = 524288

Fatal error: Out of memory (allocated 1843396608) (tried to allocate 88800 bytes) in
E:UserMy_WebsexperimentshouseshuntingemposMaps1.php on line 5

I tested this out with a smaller set of tiles and the memory used by imagecreatetruecolor() and I estimate I need 2.7GB

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You're running on a 64-bit operating system, but Apache and PHP are likely still 32-bit. If you're using mod_php, apache would be the limiting factor here.

32-bit processes are limited about 2GiB of RAM unless you used the /3GB switch and the software is aware of 3GB support.

That still leaves up about 200 MiB that seems unused, but its small enough that it can be used by various libraries that all have to be loaded in memory

As far as I know, the library usage won't show up in the committed memory, but still counts towards the 2GiB limit (much like device memory counts towards the 4GiB limit on 32-bit windows. Where installing 2 GiB graphics card brings you down to under 2GiB of usable RAM).

Most likely solution? Install a 64-bit PHP, and then dispatch it to that (using a system() call, perhaps)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...