Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP exhausted with limit at 4GB but not 2GB?

Tags:

php

nginx

I'm a developer in a large company that has some legacy code that requires a very large ammount of memory on export functions. To address this, ini_set('memory_limit', '4G'); is used.

The problem is that the script crashes with memory exaustion. If I set the limit to 2G, the script runs to the end. It doesn't even reaches 1GB peak memory usage.

Since the code is versioned and shared with the rest of the company I can't change the limit and changing it on my local install is cumbersome.

My question is: what can make a script crashes with 4GB limit but not 2GB?

PS: my setup is a virtualbox machine running Debian with nginx and php-fpm. The vm has 4GB RAM (although changing this doesn't seem to do any difference).


[update]

Created a new virtual machine with an 64 bits operation system and if I set the vm memory to 2GB it works. (If i use 4GB it doesn't). Since i'm ok with 2GB, i'll close this issue.

like image 511
upsfeup Avatar asked Dec 20 '25 05:12

upsfeup


2 Answers

It is a natural limitation: 2 or even 4 Gbs of address space are used for file mapping also which takes some memory pages.

The ultimate solution would be to use the 64-bit PHP interpreter (i.e., switch to 64-bit system, if possible).

like image 78
Viktor Latypov Avatar answered Dec 21 '25 18:12

Viktor Latypov


Maybe you are on a 32bit system?

Well if your VM only has 4GB, then you probably should give it more memory.

like image 28
JohnB Avatar answered Dec 21 '25 19:12

JohnB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!