We receive "drush Fatal error: Allowed memory size ..." for any drush command attempted (although it did work a week ago).
For instancance, both " sudo php ./drush/drush.php -l http://agaricdesign.com/ pm install adminrole" and " sudo php ./drush/drush.php -l http://agaricdesign.com/ help" give this error, alleging the allowed limit is about 16MB.
But we did increase this limit-- at least in /etc/php5/apache2/php.ini the memory limit is set higher:
memory_limit = 48M ; Maximum amount of memory a script may consume (16MB)
Is there somewhere else to set the limit for command line PHP, if there's such a distinction possible? Anyone have any insight into this error?
Thanks!
Comments
Comment #1
moshe weitzman commentedyou command line php can be different from your web php. from the command line, run php -i and it will tell you your values and tell you the location of the effective php.ini
Comment #2
mlncn commentedThanks!
That php -i is a very large output. GNU-Linux geniuses available through Agaric's good friend, the Internet, explain how to pipe its results to a separate file:
On the Debian server we were using from May First / People Link, this was the path to command line php's config:
Configuration File (php.ini) Path => /etc/php5/cli/php.ini
Another note: it did not appear to be necessary to restart anything for these changes to take affect. They just were there after saving php.ini when next looking at php -i's output.
Full writeup here.
We're hoping the "PHP Warning: Module 'json' already loaded in Unknown on line 0" doesn't affect anything, because that unknown on line zero thing seems a tad hard to debug.
Comment #3
larowlanFor those on shared hosting with no access to php.ini, you can run php -c path_to_ini_file to nominate a different ini file
Comment #4
BenGman commentedlarowlan: I tried > php -c /home/user1/bin/php/php.ini ENTER (file exists) through SSH on my shared host and the terminal stays blank (does not return to the prompt > ) unless I type Ctrl+C.
I then run php -i again to see if the configuration file was updated, but it stays as before.
Is there another way to do php -c or change the config path on a shared host?
Thanks in advance.
Comment #5
BenGman commentedThis is the solution for users in a shared hosting environment:
Configure a php.ini file, put it in your user path. You can keep it in your drush directory.
Use the following alias in .bash_profile in the user root directory then restart a bash session.
alias drush='php -c /path/to/php.ini /path/to/drush.php'
Then peform the > drush status command and you will see /path/to/php.ini under drush PHP configuration.
Comment #7
momo18 commentedI am running drush 3.0 on a hosting service and accessing it via PuTTY.
When I run drush cc for example, and I choose any of the options 1 through 4, I get the following error message.
Fatal error: Out of memory (allocated 21757952) (tried to allocate 305919 bytes) in /home/example/public_html/includes/database.inc on line 223.
The fatal error message rears its head when I execute drush in other scenarios as well.
Now, In my .bashrc I have the following drush alias defined:
alias drush='php -c /home/example/bin/drush/php.ini /home/example/bin/drush/drush.php'
In the php.ini file I have the following two commands defined:
safe_mode = Off
memory_limit = 128M
The first command is being respected, whereas the memory limit command is apparently being ignored.
Phpinfo clearly states I have 128M to use, however somehow that is being restricted. I thought I could override the system default memory_limit setting, but apparently I can't.
==========QUOTE==================
This is what my hosting provider says:
When you are executing php scripts from the webserver, it will inherit the php.ini settings from whichever path it is working in, or whichever lower directories from the path it is running in. If you look at the phpinfo script, it states where it is importing the php.ini values from when it is executed. A configuration in /home/example/bin/drush/ will not be loaded by scripts in /home/example/public_html .
The memory_limit setting for the actual server, without any other php.ini's installed is:
"""
memory_limit = 128M
"""
which an excess of what your script is trying to allocate. You may need to increase the memory_limit setting in your own php.ini files, since the behavior seems to be setting it lower to the built-in setting (whatever is set at compile time) if it is not explicitly declared in the local configuration.
====END QUOTE====================
The few drush commands I have tried on my hosting service through PuTTY are all tripping up on this memory problem.
Bye the way, could this be related to Shell Fork Bomb protection and has anyone else experience this?
I understand also, I could copy drush to /usr/local/lib and then link to it from bin, but on a shared hosting service I don't have permissions to do that. Any ideas?
Any help would be appreciated.
===================
This is an update. Bye the way, my hosting provider in the meantime fixed the problem.
This is what he said:
....
... increased the amount of memory allocated to your shell. Since it is a shared hosting environment, they are intentionally limited so that users are not able to accidentally cause server-wide disturbances.
....
Hope someone else finds this useful.
Moses
Comment #8
greg.1.anderson commentedGlad you got that all sorted out.
Comment #10
gavinengel commentedCan I use something similar to this instead (adding to line 1 of update.php)?:
ini_set('memory_limit', '96M');
(by the way, that line doesn't help Drush)
Comment #11
kaido.toomingas commented#5 works Thanks a lot.. This worked even then when my host told me there is no way to increase by myself and they wouldn't :D I tried everything else and no change until this one..
Comment #12
goodeit commentedI'm in a shared hosting situation. #5 worked for me, however it reduced the amount of interactivity I had with Drush. I no longer got success or [ok]/[error] messages, and also couldn't choose to use a dev version of a module if there was no recommended version (it would prompt me, then immediately say 'Cancelled' and quit). I believe this is due to calling drush.php directly instead of using the drush script file to wrap drush.php, although it could be due to poor configuration of the new php.ini on my part.
A better solution, in my opinion, is to use a drush.ini file to override specific php.ini settings (in this case, memory_limit). There is an example.drush.ini file in /drush/examples that worked perfectly for me. The drush.ini file can be placed in the Drush installation folder or the user's .drush folder (i.e. ~/.drush/drush.ini), and Drush will automatically find and use it.
Using drush.ini and reverting my .bashrc to alias drush="/path/to/drush" has removed all memory errors and restored the interactivity.
Comment #13
strykaizersry, bad post
Comment #14
nachocode commentedI was having the same issue with PHP7.1 CLI with
memory_limit= 128MB#12 solved the problem like a charm.