Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to override / set php options for Drush 9? #3294

Closed
frederickjh opened this Issue Jan 9, 2018 · 13 comments

Comments

Projects
None yet
2 participants
@frederickjh
Copy link
Contributor

frederickjh commented Jan 9, 2018

With the move to Drupal 8.4 I switched one of my sites to a site installed Drush 9. I also installed the Drush launcher.

Drush Launcher Version: 0.5.0
Drush Commandline Tool 9.0.0-rc1

I have the following environmental variables related to Drush set:

DRUSH_INI="/home/username/.drush/drush.ini"
DRUSH_LAUNCHER_FALLBACK="/home/username/.composer/vendor/bin/drush"
DRUSH_PHP="/opt/cpanel/ea-php71/root/usr/bin/php"

This is on a server where the php.ini for the cli sets memory_limit=32M. With Drush 8 globally installed I could use ~/.drush/drush.ini to set memory_limit=512M.

I did see in issue #2934 that the drush.ini file is ignored and that that the drush launcher does not handle drush.ini either.

I have tried unsuccessfully to run Drush 9 and increase the memory limit. Here is what I have tried using the updb to test the memory_limit=32M:

$ php -d memory_limit=512M ../vendor/bin/drush --php-options=memory_limit=512M
Drush Commandline Tool 9.0.0-rc1
. . .

It appears that --php-options is not a valid option with Drush 9 as it spits out the default help text after the above console output.

$ php -c ~/.drush/drush.ini ../vendor/bin/drush -c ~/.drush/drush.ini updb
 [error]  Drush command terminated abnormally due to an unrecoverable error.
Error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 8192 bytes) in /home/meosch/l2m.ch/releases/20171229-022429/docroot/core/lib/Drupal/Core/Extension/InfoParserDynamic.php, line 22 
 [error]  The external command could not be executed due to an application error.

So setting the PHP options in a file does not seem to work either. I made a copy of the default php.ini and then increased memory_limit=512M.


So, is there a way to set php options for Drush 9? And is is also possible to use the Drush launcher with this too?

@frederickjh

This comment has been minimized.

Copy link
Contributor Author

frederickjh commented Jan 9, 2018

Interestingly running:

php -c ~/.drush/drush.ini ../vendor/bin/drush -c ~/.drush/drush.ini php:cli

Then running: phpinfo() I see in the php info:

memory_limit => 512M => 512M

So, the php cli is seeing the php option but drush updb does not.

@weitzman

This comment has been minimized.

Copy link
Member

weitzman commented Jan 9, 2018

Drush 9 is now out of the business of setting up your PHP environment. It got too complex to maintain this.

Drush does create subprocesses for some commands (sql-sync, updb, config-pull, ...). Those subprocesses probably dont see the -c option so the subprocess gets memory starved. Thats my guess.

That doesn't really answer your question. For right now, Drush9 is declaring the question "out of scope". At minimum, I'd like to add some docs to help people who are using a constrained php environment like you are.

@frederickjh

This comment has been minimized.

Copy link
Contributor Author

frederickjh commented Jan 10, 2018

Thanks @weitzman for the reply. I tried everything I could think of my greatest hope was a bash alias for php that added the php.ini via the -c option but as you said it seems the sub processes do not see it.

I was able to get the memory_limit on the VPS PHP configuration raise to an acceptable level so I am back in business. However I do hope that a solution to this for others can be found.

@weitzman weitzman changed the title How to override / set php options for Drush 9 installed per site while using drush launcher? How to override / set php options for Drush 9? Mar 4, 2018

@weitzman

This comment has been minimized.

Copy link
Member

weitzman commented Mar 4, 2018

I think the best way to do this is to insure that the PHPRC environment variable is set to the directory containing the desired php.ini. Subprocesses get the same environment so the change persists there.

You can set the variable just for one request. See PHP Config line below:

~/reps/mass (develop *=) $ PHPRC=/tmp drush st
 Drupal version : 8.4.5                                                                  
 PHP config     : /tmp/php.ini                                                 
 PHP OS         : Darwin                                                       
 Drush script   : /Users/moshe.weitzman/bin/drush                              
 Drush version  : 9.2.1                                                        

@weitzman weitzman closed this Mar 4, 2018

@weitzman

This comment has been minimized.

Copy link
Member

weitzman commented Mar 4, 2018

now documented in install docs

@frederickjh

This comment has been minimized.

Copy link
Contributor Author

frederickjh commented Mar 5, 2018

@weitzman This works on linux in a normal bash shell but not in a Cpanel bash jailedshell.

To test on both servers I created a /tmp/php.ini file that sets the memory_limit = 128M.

Normal Linux User:

$ PHPRC=/tmp env | grep PHPRC
PHPRC=/tmp
$ PHPRC=/tmp drush st
 Drupal version : 8.4.4                                                      
 Site URI       : default                                                    
 DB driver      : mysql                                                      
 DB hostname    : db                                                         
 DB port        : 3306                                                       
 DB username    : user                                                       
 DB name        : default                                                    
 PHP binary     : /usr/bin/php7.1                                            
 PHP config     : /tmp/php.ini                                               
 PHP OS         : Linux                                                      
 Drush script   : /home/user/docker/l2mch/vendor/bin/drush             
 Drush version  : 9.1.0                                                      
 Drush temp     : /tmp                                                       
 Drush configs  : /home/user/docker/l2mch/vendor/drush/drush/drush.yml 
                  /home/user/docker/l2mch/drush/drush.yml              
 Drupal root    : /home/user/docker/l2mch/docroot                      
 Site path      : sites/default                                              
$ drush --version
Drush Launcher Version: 0.5.1
Drush Commandline Tool 9.1.0
$

Cpanel Jailed shell user

$ PHPRC=/tmp env|grep PHPRC
PHPRC=/tmp
$ PHPRC=/tmp drush st
$

The drush st command returned no output in the shell. I then tried the direct path to Drush 9 in the Drupal 8 project.

$ PHPRC=/tmp vendor/bin/drush st

Fatal error: Uncaught Error: Call to undefined function Drush\Preflight\ctype_alpha() in /home/user/example.com/releases/20180205-090119-live-0.2.0/vendor/drush/drush/src/Preflight/ArgsRemapper.php:49
Stack trace:
#0 /home/user/example.com/releases/20180205-090119-live-0.2.0/vendor/drush/drush/src/Preflight/ArgsRemapper.php(32): Drush\Preflight\ArgsRemapper->checkRemap('st', false)
#1 /home/user/example.com/releases/20180205-090119-live-0.2.0/vendor/drush/drush/src/Preflight/ArgsPreprocessor.php(55): Drush\Preflight\ArgsRemapper->remap(Array)
#2 /home/user/example.com/releases/20180205-090119-live-0.2.0/vendor/drush/drush/src/Preflight/Preflight.php(163): Drush\Preflight\ArgsPreprocessor->parse(Array, Object(Drush\Preflight\PreflightArgs))
#3 /home/user/example.com/releases/20180205-090119-live-0.2.0/vendor/drush/drush/src/Preflight/Preflight.php(229): Drush\Preflight\Preflight->preflightArgs(Array)
#4 /home/user/example.com/releases/20180205-090119-live-0.2.0/vendor/drush/drush/src/Runtime/Runtime.php(58): Drush\Preflight\Preflight->prefl in /home/user/example.com/releases/20180205-090119-live-0.2.0/vendor/drush/drush/src/Preflight/ArgsRemapper.php on line 49
$ drush --version
Drush Launcher Version: 0.5.0
Drush Commandline Tool 9.0.0-rc1
$

Let me know if there is any more information that I can supply or test I can run to help fix this.

@frederickjh

This comment has been minimized.

Copy link
Contributor Author

frederickjh commented Mar 5, 2018

Do you think the version of the Drush command line tool has anything to do with it? Just saw that one is an RC and the other is a stable release version.

@weitzman

This comment has been minimized.

Copy link
Member

weitzman commented Mar 5, 2018

Seems like the original question has now been answered.

could you edit this line and add a `\ before ctype_alpha. that may fix it. I'm not clear when that's needed since php has a fallback policy.

@weitzman

This comment has been minimized.

Copy link
Member

weitzman commented Mar 5, 2018

And yeah, 9.0.0-rc1 is quite old. Tha could be contributing to the problem. Hard to say.

@frederickjh

This comment has been minimized.

Copy link
Contributor Author

frederickjh commented Mar 7, 2018

@weitzman I made the modification that you suggested above adding / before ctype_alpha, so that the line looks like this:

if (!$sawCommand && /ctype_alpha($arg[0])) {

I also updated Drush before:

Drush Launcher Version: 0.5.0
Drush Commandline Tool 9.1.0

However still got no ouput when I run PHPRC=/tmp drush st.

@weitzman

This comment has been minimized.

Copy link
Member

weitzman commented Mar 7, 2018

slash needs to go in other direction - \

@frederickjh

This comment has been minimized.

Copy link
Contributor Author

frederickjh commented Mar 7, 2018

Sorry, I tried it again with the line if (!$sawCommand && \ctype_alpha($arg[0])) { and still no output.

@weitzman

This comment has been minimized.

Copy link
Member

weitzman commented Mar 29, 2018

Sounds like your PHP does not have the ctype extension. Thats quite rare.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.