User login

Upping memory command line PHP memory limits so you can use Drush

Searched words: 
CLI PHP Drupal shell UNIX GNU-Linux ubuntu increase php command line memory code out of mb

UPDATE: Short and sweet the error and the fix (on Ubuntu, at least) with none of the jibber-jabber below.

ben@ebony-ubuntu:~/code/anjali/drupal$ drush updatecode

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 122880 bytes) in /home/ben/code/anjali/drupal/sites/all/modules/quiz/quiz.module on line 677
Drush command could not be completed. [error]

Start editing the command line php configuration (initialization) file with:
sudo vi /etc/php5/cli/php.ini

Search for your section with /memory_limit, [return].

Then edit the memory limit line. In addition from going to 32 megabytes to 256 for the maximum available to CL PHP scripts, we tripled the max execution and max input times while we were there.

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 90     ; Maximum execution time of each script, in seconds
max_input_time = 180 ; Maximum amount of time each script may spend parsing request data
;max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 256M      ; Maximum amount of memory a script may consume (32MB)

And now back to your regularly scheduled drivel... but you should be all set with the above. You do not need to restart anything for changes to command line configuration to take effect, just try your script again.

Original title: Drush needs to be easier to use (read: I can't get it right!)

A new server, a new error.

0 stedile:~# cd /var/www/wsf2008/modules/contributed/drush/
0 stedile:/var/www/wsf2008/modules/contributed/drush# ./drush.php install login_destination
-bash: ./drush.php: Permission denied

OK, reviewing Agaric's own notes, and revising our commands, no better:

126 stedile:/var/www/wsf2008/modules/contributed/drush# cd ../
0 stedile:/var/www/wsf2008/modules/contributed# php ./drush/drush.php -l http://dev.wsf2008.net/ help
PHP Warning:  Module 'json' already loaded in Unknown on line 0

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 19456 bytes) in /var/www/wsf2008/modules/user/user.module on line 536
255 stedile:/var/www/wsf2008/modules/contributed#

Well, the answer to the memory limit question was provided to Agaric by Moshe in the drush issue queue.

Configuration File (php.ini) Path => /etc/php5/cli/php.ini
memory_limit => 16M => 16M

Also learned that "vi | php -i" is not a way to pipe something to Vi. It freezes your whole ssh session. So much for guessing an unix commands.

The correct way, from our own follow-up:

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:

php -i > phpinfo
vi phpinfo

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.

So in this file, which you can find after getting into the file with vi /etc/php5/cli/php.ini by typing /memory_lim and pressing enter:

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 60     ; Maximum execution time of each script, in seconds
max_input_time = 90 ; Maximum amount of time each script may spend parsing request data
memory_limit = 48M      ; Maximum amount of memory a script may consume (16MB)

Agaric upped it a little.

And we're going to hope the whole "json" thing doesn't matter.

And it didn't!

cd /var/www/wsf2008/modules/contributed/
php ./drush/drush.php -l http://dev.wsf2008.net/ help

Good so far...

0 stedile:/var/www/wsf2008/modules/contributed# php ./drush/drush.php -l http://dev.wsf2008.net/ pm install login_destination
PHP Warning:  Module 'json' already loaded in Unknown on line 0
Project login_destination successfully installed (version 5.x-1.0).

Golden!

Complete the cycle of adding it to our repository, reverse of our old approach:

... uh ....

Blast, it went and put it in sites/wsf2008.net/modules

Not desired. The readme provides only one recourse, "drush help pm install." So, get back to where we once belonged:

cd /var/www/wsf2008/modules/contributed/

(Note: that will not be where you have your drush installed, unlike Agaric and our 4.7-era structure, you will probably have it somewhere sensible like sites/all/modules).

And run the drush command (also we should have a symlink to where drush is rather than having to be in position or give the path to the command like this)

php ./drush/drush.php -l http://dev.wsf2008.net/ help pm install

Usage: drush [options] pm install ...

is the short name of a project hosted on drupal.org.
So far, only modules are supported.
The modules will be installed into the sites/all/modules directory.

To use the modules, they still have to be activated on the normal module administration page.

OK, so it's not installing in sites/all/modules even though it says it will.

However, I guess because we don't have a true multisite going here, drush seems to work without the -l modifier:

0 stedile:/var/www/wsf2008/modules/contributed# php ./drush/drush.php pm install login_destination
PHP Warning:  Module 'json' already loaded in Unknown on line 0
Project login_destination successfully installed (version 5.x-1.0).

All right, and it didn't say it's already installed so we should be fine.

0 stedile:/var/www/wsf2008/modules/contributed# cd ../../sites/all/modules/
0 stedile:/var/www/wsf2008/sites/all/modules# ls -la

drwxr-sr-x 2 27743 27744 4096 2007-04-20 09:45 login_destination

Yup! It's there! No idea who user 27743 and group 27744 are, though.

Now, as we were saying, to commit this to Agaric's repository (sites/all for drush edition... eventually all our modules will migrate over there, once we verify that modules in sites/specific directory )

0 stedile:/var/www/wsf2008/sites/all/modules# svn add login_destination

A login_destination
A login_destination/login_destination.module
A login_destination/login_destination.info
A login_destination/README.txt
A login_destination/LICENSE.txt

And then the svn commit didn't work 'cause this isn't the right checkout.

(liveblogging: feel the excitement) I3IVIIVI (7:47:47 PM): right now I'm drushifying Stedile

So, steps you will never have to take but Agaric did this one time:

0 stedile:/var/www/wsf2008/sites/all/modules# rm -rf modules/
0 stedile:/var/www/wsf2008/sites/all/modules# svn co https://66.135.37.243/srv/svn/agaric/drupal-contrib/5/modules-all modules
0 stedile:/var/www/wsf2008/sites/all/modules# php ./drush/drush.php pm install login_destination
0 stedile:/var/www/wsf2008/sites/all/modules# svn add login_destination/
0 stedile:/var/www/wsf2008/sites/all/modules# svn commit -m "added login destination module via Drush"

Fantastic!

The only part of this that bothers me, is shouldn't I have had to log into our repository or something somehow?

Resolution

Comments

Piping to Vi

Using Vim on Linux, you can pipe output to it directly using "-" to indicate STDIN

php -i | vim -

Note that on Ubuntu and most Linux distros, vi is the same as vim.

Just an FYI for ya

Didn't realize command-line PHP had its own php.ini

Your post taught me that I had to modify a second php.ini file. Thanks!

another solution

I saw this solution

php -dmemory_limit=512M -dsafe_mode=Off your.php

from http://php.net/manual/en/features.commandline.php

looks good if you can't change your ini file..

Perfect!

Thank you! It's been bugging all morning where to set that value.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.