4

I am using drush, which is a command-line php app to manage a drupal website. I am running a command to import a lot of data, which is causing me to hit php's memory limit.

PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted ...

Which is 512MB if I'm doing the math correctly (536870912 / 1024 / 1024 = 512). I've changed the directive in the php.ini that drush uses:

$> drush status
  ...
  PHP configuration      :  /etc/php5/cli/php.ini 
$> grep memory /etc/php5/cli/php.ini 
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 1024M 

But I'm still hitting the 512 MB limit! I am running in a virtual machine, whose memory settings I changed from 512 to 1025 MB of RAM to allow drush to run.

$> free -m
             total       used       free     shared    buffers     cached
Mem:          1010        578        431          0         14        392
-/+ buffers/cache:        172        837
Swap:          382          0        382

So it says it has some 431 MB free, now that I've bumped the vm up to 1024. I guess half the memory is being used to run the GUI, but I don't understand how the GUI was running okay when the vm had 512 MB of ram.

Why is the PHP cli still hitting a 512 MB memory limit? If it was hitting a system memory limit, shouldn't it die around 431MB, which is what the free command says is available?

user13743
  • 1,751

3 Answers3

5

Most likely, you have more than one php.ini file (check something like /etc/php5/cli) and are editing the wrong one or you have a ini_set('memory_limit', '512M'); setting in a settings.php file or the like that is getting included.

3

For other people who google this question like me - run this command:

php --ini

To see which configuration php-cli is using. You will see something like this:

Loaded Configuration File:         /etc/php/7.1/cli/php.ini

Or like this:

Loaded Configuration File:         /opt/php-7.0.26/etc/php.ini

Maybe you are trying to change configuration in a wrong file.

0

On Mac for instance

/etc/php5/cli is for command line, so you need to change /etc/php5/cgi/php.ini

That should work!

7ochem
  • 162