Hi all,

admin/reports/status and phpinfo.php tell me that my PHP memory limit is 256M but when using Drush I m getting memory error messages re 64M eg
Fatal error: Out of memory (allocated 69468160) (tried to allocate 122880 bytes) in /home...

Any suggestions please?

Thank you

Comments

undersound3’s picture

I think this will help you out
http://drupal.org/node/457416

Juc1’s picture

@ undersound3

Thanks for that link. I mentioned the link to my (shared hosting) host (see below).

Can I just please check - is it possible for Drupal to fix or over-ride the PHP memory limit (I think not)?

Thanks

On Sat, Jul 14, 2012 at 1:26 PM,
From support@.....host.com
To ...@gmail.com

Hi

Like I said, the system PHP memory limit is already set to 256MB. This is
being overridden somewhere within your code or the code that you're running.

You can see the system PHP variables by running 'php -i' from the command
line or by executing phpinfo().

Kind regards,

On Sat, Jul 14, 2012 at 1:22 PM
From ...@gmail.com
To support@.....host.com

Can you please check the the file /etc/php5/cli/php.ini as mentioned
in the link below.

Thank you,

http://drupal.org/node/457416 =

modify the file /etc/php5/cli/php.ini
search for "memory_limit" and change it from the default of 32M to
something larger...

It's not just php.ini that counts. PHP config settings can be set in
multiple places. Settings on the same server may or may not take
effect or not depending on the calling user, script location, PHP
version and binary (CLI, CGI, apache module etc) involved. Testing php
--info may not show you the relevant values because it may not load
settings specific to your Drupal site....

Several of the above comments seem to be having specific issues with
Drush on shared hosting environments or CPanel / WHM / etc setups.
Please consult your hosting documentation if you are having similar
issues, and if you are experiencing resource limits specific to Drush,
when requesting support from your hosting company make sure to alert
them to the fact that you are running PHP from CLI.

Jaypan’s picture

Have you created a drush.ini with the memory limit in the root of your Drush folder? Drush doesn't use the php memory limit. You can edit the file drush/examples/examples.drush.ini, change the memory limit, and save it as drush/drush.ini. You won't be able to override your host's 256mb though, that will be the maximum if you are on shared hosting.

Juc1’s picture

@ Jaypan thanks for your help - no I haven't created a drush.ini file. But before I do that is there any command that will display the current memory limit that Drush is using?

Thanks

Jaypan’s picture

Maybe.

Juc1’s picture

more memory problems = http://drupal.org/node/1289956

undersound3’s picture

So which path is shown under PHP configuration when you run the command drush status

Juc1’s picture

# drush status
PHP configuration      :  /usr/local/lib/php.ini
                          /home/..../drush/drush.ini

I added the second file myself but it doesn't seem to help.

Thanks

undersound3’s picture

And which location for php.ini is shown in phpinfo.php?

Juc1’s picture

Loaded Configuration File /usr/local/lib/php.ini

screenshots = http://jusand.co.uk/drush

Thanks

undersound3’s picture

Sorry but then I don't know what's causing this.
Perhaps someone in the drush issues section can help you better.

Ace Cooper’s picture

In my case I tried to install Drush 5.x-dev (dated August 7, 2012) on a ukrainian shared hosting Hvosting.ua
I have a user-level SSH access to the server.

I started with downloading and unpacking:

# cd ~
# wget http://ftp.drupal.org/files/projects/drush-All-versions-5.x-dev.zip 
# unzip drush-All-versions-5.x-dev.zip

After running # php ~/drush/drush.php status in the drupal directory I got memory limit error:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 32 bytes) in /home/h30424/data/www/mmh6.info/includes/cache.inc on line 405
Drush command terminated abnormally due to an unrecoverable error. 

So, the limit on my php.ini was 32 Mb only:

#which php
/usr/bin/php
# /usr/bin/php -i |grep memory_limit
memory_limit => 32M => 32M
suhosin.memory_limit => 0 => 0 

Didn't believe it, because i clearly remember setting memory_limit to maximum allowed 256 Mb through ISP Manager.
But then I noticed, that my home-folder contains a php-bin directory.
Inside I found the launch script for php5-cgi and the php.ini, created with ISP Manager, containing my manually set 256 Mb memory_limit.

I was in luck, because php5-cgi had 128 Mb limit by default and 256 Mb limit with my settings:

# which php5-cgi
/usr/bin/php5-cgi
/usr/bin/php5-cgi -i |grep memory_limit
<tr><td class="e">memory_limit</td><td class="v">128M</td><td class="v">128M</td></tr>
<tr><td class="e">suhosin.memory_limit</td><td class="v">0</td><td class="v">0</td></tr>

Well, html output was unexpected, but I got me a php version I could work with.
So I added this to my ~/.bashrc alias section:
alias drush="/usr/bin/php5-cgi -q ~/drush/drush.php"

The battle wasn't over - drush was working correctly, but still showing some warnings (screenshot 1):

# drush dis -y login_destination
The following extensions will be disabled: login_destination
Do you really want to continue? (y/n): y
<br />
<b>Notice</b>:  Use of undefined constant STDERR - assumed 'STDERR' in <b>/home/h30424/data/drush/includes/drush.inc</b> on line <b>1598</b><br />
<br />
<b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource in <b>/home/h30424/data/drush/includes/output.inc</b> on line <b>34</b><br /> 

First of all, the wrong constant declaration STDERR should just be surrounded with '...' :
vi ~/drush/includes/drush.inc
So I added single quotes on line 1598 like this: drush_print($message, 0, 'STDERR'); and that first notice went away.

For the second warning I had to replace advanced output with more simple alternative:
vi ~/drush/includes/output.inc
It seems that php5-cgi knows nothing about $handle.
Replace the block from line 34 to line 38:

if (isset($handle)) {
    fwrite($handle, $msg);
  }
  else {
    print $msg;
  }

into just this single line:
print $msg;

And now drush became nice and helpful as always, even on my shared hosting (screenshot 2).

What we know shapes who we are.

Ace Cooper’s picture

Somewhere after first discovering memory_limit on standard php I tried to hack my way through it by defining new memory limit for drush.
I copied the example drushrc config into the working directory:
# cp ~/drush/examples/example.drushrc.php into ~/.drush/drushrc.php
And added at the very bottom of drushrc.php file:
ini_set('memory_limit','256M');
But that was construed by suhosin as an attack and hence - rejected:

># /usr/bin/php ~/drush/drush.php status
ALERT - script tried to increase memory_limit to 3145728000 bytes which is above the allowed value (attacker 'REMOTE_ADDR not set', file '/home/h30424/data/.drush/drushrc.php', line 343)

So I went looking for a legit bypass through php5-cgi.

In conclusion, when locked on shared hosting with no rights to edit global php.ini or suhosin limitations - try checking for different variations of php:
<code>php -i |grep memory_limit

php5 -i |grep memory_limit
php5-cli -i |grep memory_limit
php5-cgi -i |grep memory_limit
If you are lucky - one of them will have higher memory_limit setting, that will allow you to use Drush and enjoy Drupal even more!

What we know shapes who we are.