views:

58

answers:

1

I need to run a PHP CLI script and give it a LOT of memory (it's an automatic documentation generator that needs to cover a large code base). I have a powerful machine and have allocated 5GB to php, both in php.ini and in an inline ini_set('memory_limit','5120M') declaration in the script file.

If I add these lines to top of the script:

phpinfo();
exit();

... it claims that it has a memory limit of 5120M, as I specified.

But the script still errors out, saying

Fatal error: Allowed memory size of 1073741824 bytes exhausted

... which is 1GB, not 5GB as I specified.

Is there any other place that the script might be looking to determine its memory limit? This is running in Fedora Linux.

(Yes, the ultimate solution may be to rewrite the script to be more efficient, but I didn't write it in the first place, so before I resort to that, I want to just throw resources at it and see if that works.)

+2  A: 

The heap limit property is a size_t, which is 32 bits on a 32-bit machine. If this is in bytes, this would limit the memory limit to 4 GB. You may try running it on a 64 bit machine, with 64-bit PHP.

Edit: confirmed, heap->limit is a size_t (unsigned int) and is in bytes. A memory_limit of -1 sets the heap->limit to 4GB, and does not disable it as the documentation implies. Setting it to 5GB makes it wrap around to 1GB.

Sjoerd
Its like rolling over the scores on the old video games!
gnarf
I ran an allocation check on a 64 bit machine, but my 64 bit php binary chokes after 490 Megs...(Which is more than the previous limit of 128M... but way less than the new set limit of 5120M...)
ZJR