Index: drush.php
===================================================================
RCS file: /cvs/drupal/contributions/modules/drush/drush.php,v
retrieving revision 1.60
diff -u -p -r1.60 drush.php
--- drush.php	16 Apr 2009 02:48:43 -0000	1.60
+++ drush.php	22 Apr 2009 10:51:22 -0000
@@ -11,7 +11,7 @@
 
 // Terminate immediately unless invoked as a command line script
 if (!drush_verify_cli()) {
-  die('drush.php is designed to run via the command line.');
+  die("drush.php is designed to run via the command line.\n\n");
 }
 
 define('DRUSH_BASE_PATH', dirname(__FILE__));
@@ -21,8 +21,7 @@ require_once DRUSH_BASE_PATH . '/include
 require_once DRUSH_BASE_PATH . '/includes/backend.inc';
 require_once DRUSH_BASE_PATH . '/includes/context.inc';
 
-drush_set_context('argc', $GLOBALS['argc']);
-drush_set_context('argv', $GLOBALS['argv']);
+drush_get_args();
 exit(drush_main());
 
 /**
@@ -37,7 +36,37 @@ exit(drush_main());
  *   and false if being run through cgi or mod_php.
  */
 function drush_verify_cli() {
-  return (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0));
+  return (php_sapi_name() == 'cli' or php_sapi_name() == 'cgi-fcgi' or (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0));
+}
+
+/**
+ * Get the arguments from the global environment variables.
+ */
+function drush_get_args() {
+  global $argc, $argv, $_SERVER, $_GET;
+  if (isset($argv) && isset($argc)) {
+    // Most of the time when PHP runs as CLI this is fine.
+    drush_set_context('argc', $argc);
+    drush_set_context('argv', $argv);
+  }
+  elseif (php_sapi_name() == 'cgi-fcgi') {
+    // When PHP executes in fast CGI mode, we need to immitate the CLI args.
+    $args = array($_SERVER['_']);
+    foreach ($_GET as $key => $value) {
+      if (empty($value)) {
+        $args[] = $key;
+      }
+      else {
+        $args[] = "$key=$value";
+      }
+    }
+    drush_set_context('argc', count($args));
+    drush_set_context('argv', $args);
+  }
+  else {
+    // Drush doesn't yet support other modes.
+    die("drush.php couldn't find the arguments.\n\n");
+  }
 }
 
 /**
Index: includes/environment.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/drush/includes/environment.inc,v
retrieving revision 1.20
diff -u -p -r1.20 environment.inc
--- includes/environment.inc	18 Apr 2009 00:09:02 -0000	1.20
+++ includes/environment.inc	22 Apr 2009 10:51:22 -0000
@@ -483,6 +483,7 @@ function _drush_bootstrap_drupal_configu
          $creds['driver'] = $parts['scheme'];
          $creds['user'] = $parts['user'];
          $creds['host'] = $parts['host'];
+         $creds['port'] = $parts['port'];
          $creds['pass'] = $parts['pass'];
          $creds['name'] = trim($parts['path'], '/');
        }
@@ -493,6 +494,7 @@ function _drush_bootstrap_drupal_configu
          $creds['driver'] = $conn['driver'];
          $creds['user'] = $conn['username'];
          $creds['host'] = $conn['host'];
+         $creds['port'] = $conn['port'];
          $creds['name'] = $conn['database'];
          $creds['pass'] = $conn['password'];
        }
@@ -695,7 +697,10 @@ function drush_valid_db_credentials() {
     }
 
     $constr = sprintf("%s:dbname=%s;host=%s", $type, $creds['name'], $creds['host']);
-    
+    if (isset($creds['port'])) {
+      $constr .= sprintf(";port=%d", $creds['port']);
+    }
+
     try {
       $db = new PDO($constr, $creds['user'], $creds['pass']);
       $db = null;
