How else can a CLI PHP script determine its memory limit?

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

If I add these lines to the top of the script:

 phpinfo(); exit(); 

... he claims to have a 5120M memory limit, as I pointed out.

But the script still throws an error saying

 Fatal error: Allowed memory size of 1073741824 bytes exhausted 

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

Is there another place the script might look to determine its memory limit? This works on Fedora Linux.

(Yes, the final solution may be to rewrite the script to be more efficient, but I did not write it in the first place, so before resorting to this, I just want to throw resources on it and see if this works.)

+4
source share
1 answer

The heap restriction property is size_t, 32 bits on a 32-bit machine. If these are bytes, this will limit the memory limit to 4 GB. You can try running it on a 64-bit machine with 64-bit PHP.

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

+5
source

Source: https://habr.com/ru/post/1316664/


All Articles