Checklist:

  1. searched issue queue multiple times with various search options, filters
  2. Rechecked on HEAD drush
  3. Debug output
  4. drush status
  5. Checked drush topic, FAQ etc.

I am unable to get drush to use a different php binary when specifying the --php option:

Alans-MacBook-Pro:src alan$ drush --php=/Applications/acquia-drupal/php/bin/php  -d ev 'echo phpversion() . "\n"'
Bootstrap to phase 0. [0 sec, 3.26 MB]                               [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.01 sec, 3.48 MB] [bootstrap]
Cache HIT cid: 5.0-dev-commandfiles-0-d10ae5a6475efaedc9c59c8e61a8894d [0.01 sec, 3.49 MB]                                                                                       [debug]
Found command: php-eval (commandfile=core) [0.03 sec, 7.51 MB]                                                                                                               [bootstrap]
5.3.6
Command dispatch complete [0.03 sec, 7.52 MB]                                                                                                                                   [notice]
Peak memory usage was 9.03 MB [0.03 sec, 7.53 MB]                                                                                                                               [memory]

Alans-MacBook-Pro:src alan$ drush --php=/usr/bin/php  -d ev 'echo phpversion() . "\n"'
Bootstrap to phase 0. [0 sec, 3.25 MB]                               [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.01 sec, 3.48 MB] [bootstrap]
Cache HIT cid: 5.0-dev-commandfiles-0-d10ae5a6475efaedc9c59c8e61a8894d [0.01 sec, 3.49 MB]                                                                                       [debug]
Found command: php-eval (commandfile=core) [0.03 sec, 7.51 MB]                                                                                                               [bootstrap]
5.3.6
Command dispatch complete [0.03 sec, 7.52 MB]                                                                                                                                   [notice]
Peak memory usage was 9.03 MB [0.04 sec, 7.53 MB]                                                                                                                               [memory]

Alans-MacBook-Pro:src alan$ /usr/bin/php -v
PHP 5.3.6 with Suhosin-Patch (cli) (built: Jun 16 2011 22:26:57) 
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

Alans-MacBook-Pro:src alan$ /Applications/acquia-drupal/php/bin/php -v
PHP 5.2.17 (cli) (built: Jun 30 2011 12:12:11) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies

Alans-MacBook-Pro:src alan$ drush status
 PHP configuration     :  /private/etc/php.ini 
 Drush version         :  5.0-dev              
 Drush configuration   :                       
 Drush alias files     :                       

Reading through the initial bash script (drush), I don't see anywhere where this --php option would be handled, so it almost suggests that this may be a deprecated option, not removed from drush help. Some internals still use it though (eg to specify the interpreter to subcommands).

i can force drush to use a different binary by setting the DRUSH_PHP environment variable.

I can probably supply a patch to make it honour the option, but wanted to check first of all that this is not by design.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

greg.1.anderson’s picture

You are correct; the bash drush script uses --php and --php-options to tell the php drush script which php command and options to use when re-launching drush directly. The bash drush script currently does not parse or act on command line options at all.

It seems sensible to have the script check for these options. What do other maintainers think about adding cli option parsing to the drush script?

greg.1.anderson’s picture

Component: Base system (internal API) » Documentation
Category: bug » task

I sort of think we should leave the drush script as it is, and mark --php and --php-options 'hidden' to avoid confusion (keep them out of help). The environment variable should be documented in drush topic or global options help.

Alan Evans’s picture

For what it's worth, I would have found the option of switching the php binary useful earlier today, but to be honest, setting the environment variable is just as easy.

It does still strike me that the option could cause some inconsistency if you explicitly pass the --php option on the command line and it happens not to match the environment variable or `which php` : you could end up running the initial command with the default php interpreter and all subcommands with a different one that you specified with the --php option. I can't imagine a situation where that's good. But then again, if you hide the --php option completely and only use the environment variable, then you can ensure consistency that way.

If you think this isn't an issue then I'm happy with the idea of hiding it and adding docs on the env variable.

moshe weitzman’s picture

Assigned: Unassigned » greg.1.anderson

Not sure what we should do here, if anything. --php-options is not hidden at this time.

greg.1.anderson’s picture

I don't know if marking php-options hidden is the right thing to do, because it does work if you put them in your alias file. Kind of obscure...

moshe weitzman’s picture

Status: Active » Fixed

i removed --php-options from the readme.txt. readme already mentions DRUSH_PHP enivonment variable and php and php-options remain documented in example site aliases file.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

moshe weitzman’s picture

Version: » 8.x-6.x-dev
Status: Closed (fixed) » Needs review
FileSize
720 bytes

Actually, I think we should remove the 'php' item from example.aliases.drushrc.php. One might read it and think that Drush will initially use the specified php when using a remote alias. Thats not so - the only thing that affects which php is initially used here is the DRUSH_PHP environment variable. Drush site aliases currently provide no way to control which PHP gets used, sadly.

Patch attached.

greg.1.anderson’s picture

Actually, we are almost there with this code in backend.inc:

    $php = array_key_exists('php', $site_record) ? $site_record['php'] : (array_key_exists('php', $command_options) ? $command_options['php'] : NULL);
    $drush_command_path = drush_build_drush_command($drush_path, $php, $os, array_key_exists('remote-host', $site_record));

The problem is that drush_build_drush_command will ignore $php, favoring the 'drush' script instead, when array_key_exists('remote-host', $site_record) evaluates to true. We could easily change this behavior if we forced this parameter to FALSE when the site record provides both a php and a drush path (since calling drush via php requires the full path to the drush script, and this might not be the same on the remote machine as it is on the local machine).

Some additional work needs to be done to determine if php-options can really be passed through cleanly still; I'm not sure that this still works right.

If we just yank the documentation, you should also remove php-options from the list (unless testing confirms that it's already working correctly.)

moshe weitzman’s picture

FileSize
586 bytes

You gave me an idea. Attached 1 line patch does the trick for me, since I am not pointing to drush.php explicitly. I didn't even realize that we supported that.

greg.1.anderson’s picture

I don't have time to test, but #10 looks really good to me.

moshe weitzman’s picture

Title: Drush ignores --php option to specify the php binary to use » Drush ignores php item in site aliases which specifies the php binary to use
Component: Documentation » Base system (internal API)
Category: task » bug
Status: Needs review » Fixed

Committed, with slight update to example.aliases file.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.