Index: drush/src/Preflight/RedispatchToSiteLocal.php =================================================================== --- a/src/Preflight/RedispatchToSiteLocal.php +++ b/src/Preflight/RedispatchToSiteLocal.php @@ -30,7 +30,7 @@ class RedispatchToSiteLocal { // Try to find the site-local Drush. If there is none, we are done. - $siteLocalDrush = static::findSiteLocalDrush($root); + $siteLocalDrush = realpath(static::findSiteLocalDrush($root)); if (!$siteLocalDrush) { return [false, DrushCommands::EXIT_SUCCESS]; } @@ -46,18 +46,38 @@ class RedispatchToSiteLocal return [false, DrushCommands::EXIT_SUCCESS]; } + if (dirname($argv[0]) == dirname($siteLocalDrush)) { + return [false, DrushCommands::EXIT_SUCCESS]; + } + + if(array_key_exists('_composer_bin_dir', $GLOBALS) && + dirname($argv[0]) == $GLOBALS['_composer_bin_dir']) { + return [false, DrushCommands::EXIT_SUCCESS]; + } + // Redispatch! - $command = escapeshellarg($siteLocalDrush); - $preflightLog->log(dt('Redispatch to site-local Drush: !cmd.', ['!cmd' => $command])); - array_shift($argv); - $args = array_map( - function ($item) { - return escapeshellarg($item); - }, - $argv - ); - $command .= ' ' . implode(' ', $args); - passthru($command, $status); + print 'DEBUG: Redispatch!' . PHP_EOL; + + // We have to reconstruct the whole command line, because + // at this point, we will take over the control on running the Drush command + $command = PHP_BINARY; + // Add some PHP arguments + // TODO Implement it at the SiteAlias\ProcessManager too + $php_args = [ + '-d', 'memory_limit=-1', + '-d', 'allow_url_fopen=1', + '-d', 'display_errors=1', + '-d', 'error_reporting=' . strval(E_ALL & ~E_NOTICE & ~E_DEPRECATED), + ]; + + $args = array_merge($php_args, $argv); + print_r(['command' => $command, 'args' => $args, 'siteLocalDrush' => $siteLocalDrush]); + + $preflightLog->log(dt('Redispatch to site-local Drush: !cmd.', ['!cmd' => $argv[0]])); + + $ret = pcntl_exec($command, $args); + $status = is_null($ret); + return [true, $status]; } Index: drush/src/SiteAlias/ProcessManager.php =================================================================== --- a/src/SiteAlias/ProcessManager.php +++ b/src/SiteAlias/ProcessManager.php @@ -63,6 +63,21 @@ class ProcessManager extends Consolidati // The executable is always 'drush' (at some path or another) array_unshift($args, $drushScript); + // TODO Implement some PHP argument bypassing + $essential_php_args = [ + 'allow_url_fopen' => 1, + 'memory_limit' => ini_get('memory_limit'), + ]; + + foreach($essential_php_args as $key => $value) { + array_unshift($args, "{$key}={$value}"); + array_unshift($args, '-d'); + } + + if($drushScript != 'drush' && defined('PHP_BINARY')) { + array_unshift($args, PHP_BINARY); + } + return $this->siteProcess($siteAlias, $args, $options, $options_double_dash); }