When running drush-7.x-5.0-rc2 outside a Drupal installation, and thus the $server_uri passed to drush_conf_path() is emptystring, I get a constant stream of PHP warnings: Unable to parse URL environment.inc:295.

I've attached a patch, to avoid doing parse_url() on emptystrings and thus avoid generating these warnings.

Comments

moshe weitzman’s picture

Status: Needs review » Postponed (maintainer needs more info)

Please follow the advice here when posting support requests.

greg.1.anderson’s picture

Category: bug » support
Status: Postponed (maintainer needs more info) » Needs review

parse_url does not seem to work as described in #0.

$ drush ev 'print ($a);'
Undefined variable: a core.drush.inc(983) : eval()'d code:1 [warning]
$ drush ev 'print_r(parse_url(""));'
Array
(
    [path] => 
)
$ drush ev 'print_r(parse_url(NULL));'
Array
(
    [path] => 
)

I think the suggested patch is unnecessary.

greg.1.anderson’s picture

Status: Needs review » Postponed (maintainer needs more info)

Did not mean to adjust status.

smokris’s picture

Category: support » bug
Status: Postponed (maintainer needs more info) » Needs review

@greg.1.anderson: My original post was unclear; it's not parse_url("") that's the problem, it's parse_url("http://") (which is what drush tries to do when $server_uri is emptystring). I get this output:

$ ./drush ev 'print_r(parse_url("http://"));'
parse_url(http://): Unable to parse URL core.drush.inc(983) : eval()'d code:1                     [warning]

@mosheweitzman: Sorry, I missed steps 3 and 4. Here's the output when running the command with --debug:

$ ./drush --debug make site.make site-test
Bootstrap to phase 0. [0 sec, 2.8 MB]                                [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0 sec, 3 MB]       [bootstrap]
Cache HIT cid: 5.0-dev-commandfiles-0-94589c40d3d53097f7e881bbc9e5e627 [0.01 sec, 3.02 MB]            [debug]
Bootstrap to phase 0. [0.03 sec, 6.91 MB]                                                         [bootstrap]
Bootstrap to phase 0. [0.04 sec, 6.92 MB]                                                         [bootstrap]
Found command: make (commandfile=make) [0.04 sec, 6.92 MB]                                        [bootstrap]
Loading release_info engine. [0.05 sec, 6.93 MB]                                                     [notice]
Downloading release history from http://updates.drupal.org/release-history/drupal/6.x [0.06 sec,     [notice]
7.25 MB]
http---updates.drupal.org-release-history-drupal-6.x retrieved from cache. [0.06 sec, 7.25 MB]       [notice]

[... a bunch of other projects, nothing interesting ...]

Downloading release history from http://updates.drupal.org/release-history/zen/6.x [0.09 sec, 7.42   [notice]
MB]
http---updates.drupal.org-release-history-zen-6.x retrieved from cache. [0.09 sec, 7.42 MB]          [notice]
Backend invoke: /usr/bin/php /home/smokris/2/drush/drush.php --php=/usr/bin/php  --yes --verbose    [command]
--debug --root= --uri= pm-download drupal-6.24  
--destination=/tmp/make_tmp_1328996757_4f36e195531f5 --package-handler=wget --cache
--drupal-project-rename=__build__ --backend=2 2>&1 [0.14 sec, 7.44 MB]
/usr/bin/php /home/smokris/2/drush/drush.php --php=/usr/bin/php  --yes --verbose --debug --root=     [notice]
--uri= pm-download drupal-6.24   --destination=/tmp/make_tmp_1328996757_4f36e195531f5
--package-handler=wget --cache --drupal-project-rename=__build__ --backend=2 2>&1 [0.14 sec, 7.44
MB]
Bootstrap to phase 0. [0.33 sec, 6.92 MB]                                                         [bootstrap]
parse_url(http://): Unable to parse URL environment.inc:295 [0.33 sec, 6.92 MB]                   [warning]
parse_url(http://): Unable to parse URL environment.inc:295 [0.34 sec, 6.93 MB]                   [warning]
parse_url(http://): Unable to parse URL environment.inc:295 [0.34 sec, 6.93 MB]                   [warning]

And the output of drush status:

$ ./drush status
 PHP configuration     :  /etc/php.ini 
 Drush version         :  5.0-dev      
 Drush configuration   :               

Also possibly useful:

$ which --all php
/usr/bin/php
$ php --version
PHP 5.2.17 (cli) (built: Feb 15 2011 11:30:25) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
greg.1.anderson’s picture

Category: bug » support
Status: Needs review » Postponed (maintainer needs more info)

This is a php 5.2 issue. I don't get a warning for parse_url("http://") on my php 5.3 install, but I dug up an old server that still had 5.2 on it and confirmed the warning with drush ev 'print_r(parse_url("http://"));'.

However, I do -not- see this warning when I run drush (today's master) on php 5.2. I do see warnings when I run drush version --uri='http://' (only on php 5.2), so perhaps this is a config problem.

smokris’s picture

Category: support » bug
Status: Postponed (maintainer needs more info) » Needs review

Er, how is this a config problem? I have no Drush config, and a standard PHP 5.2 config — isn't it a bug if Drush throws PHP warnings out-of-the-box?

Here's a shell transcript, demonstrating the problem occurring on PHP 5.2.9 (this time on a different, older, box) with the current Drush master branch:

$ which --all php
/usr/bin/php
$ php --version
PHP 5.2.9 (cli) (built: Apr 17 2009 03:45:58) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
$ git clone --branch master http://git.drupal.org/project/drush.git
$ echo -e "core=6.x\napi=2\nprojects[]=drupal" > test.make
$ ./drush/drush make test.make testdir
parse_url(http://): Unable to parse URL environment.inc:295          [warning]
parse_url(http://): Unable to parse URL environment.inc:295          [warning]
drupal-6.24 downloaded from                                                    [ok]
http://ftp.drupal.org/files/projects/drupal-6.24.tar.gz
greg.1.anderson’s picture

Status: Needs review » Needs work

Can't reproduce what you're seeing. Also, if the problem is parse_url('http://'), I don't see how the provided patch helps fix that problem.

smokris’s picture

Status: Needs work » Needs review

Here's the relevant bit of code as it currently exists in Drush master:

288 function drush_conf_path($server_uri, $require_settings = TRUE) {
289   $drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT');
290   if(!isset($drupal_root) || !isset($server_uri)) {
291     return NULL;
292   }
293   $parsed_uri = parse_url($server_uri);
294   if (is_array($parsed_uri) && !array_key_exists('scheme', $parsed_uri)) {
295     $parsed_uri = parse_url('http://' . $server_uri);
296   }

When the $server_uri passed to drush_conf_path() is emptystring, the first conditional, line 290, is false, so we jump to line 293. Line 293 works fine (no PHP warning), and returns an array. The conditional on line 294 evaluates to true (parse_url('') returns an array which does not include a scheme), so we try to do parse_url('http://' . $server_uri), which, since $server_uri is emptystring, evaluates to parse_url('http://'), which, as you confirmed in #5, generates a warning.

The patch in the original post modifies the first conditional, line 290, so that it evaluates to true when $server_uri is emptystring, so that we never try to parse the bogus 'http://' url. Since the patch avoids trying to parse the bogus 'http://' url, which produces a PHP warning, the patch therefore solves the problem described in the original post.

greg.1.anderson’s picture

Status: Needs review » Needs work

I think that changing the 'isset' tests to 'empty' would be better.

smokris’s picture

Status: Needs work » Needs review
StatusFileSize
new526 bytes

Sure. How's this?

greg.1.anderson’s picture

Status: Needs review » Fixed

Committed. Thanks.

smokris’s picture

Great. Thank you.

paskainos’s picture

I experienced this problem too with Drush 7.x-5.0-rc2 / PHP 5.2.17. Switched to Drush 5.0-dev.

Status: Fixed » Closed (fixed)

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