From 7aa7c3ced3e34cd9067963144dd02108bc1a936f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 22 Jan 2017 19:03:22 +0100 Subject: [PATCH] Forward composer memory_limit to child processes, fixes #6075 --- .../EventDispatcher/EventDispatcher.php | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Composer/EventDispatcher/EventDispatcher.php b/src/Composer/EventDispatcher/EventDispatcher.php index fdb008668..b74d34858 100644 --- a/src/Composer/EventDispatcher/EventDispatcher.php +++ b/src/Composer/EventDispatcher/EventDispatcher.php @@ -175,12 +175,7 @@ class EventDispatcher $args = $event->getArguments(); $flags = $event->getFlags(); if (substr($callable, 0, 10) === '@composer ') { - $finder = new PhpExecutableFinder(); - $phpPath = $finder->find(); - if (!$phpPath) { - throw new \RuntimeException('Failed to locate PHP binary to execute '.$scriptName); - } - $exec = ProcessExecutor::escape($phpPath) . ' ' . ProcessExecutor::escape(getenv('COMPOSER_BINARY')) . substr($callable, 9); + $exec = $this->getPhpExecCommand() . ' ' . ProcessExecutor::escape(getenv('COMPOSER_BINARY')) . substr($callable, 9); if (0 !== ($exitCode = $this->process->execute($exec))) { $this->io->writeError(sprintf('Script %s handling the %s event returned with error code '.$exitCode.'', $callable, $event->getName())); @@ -234,12 +229,7 @@ class EventDispatcher } if (substr($exec, 0, 5) === '@php ') { - $finder = new PhpExecutableFinder(); - $phpPath = $finder->find(); - if (!$phpPath) { - throw new \RuntimeException('Failed to locate PHP binary to execute "'.$exec.'"'); - } - $exec = $phpPath . ' ' . substr($exec, 5); + $exec = $this->getPhpExecCommand() . ' ' . substr($exec, 5); } if (0 !== ($exitCode = $this->process->execute($exec))) { @@ -259,6 +249,19 @@ class EventDispatcher return $return; } + protected function getPhpExecCommand() + { + $finder = new PhpExecutableFinder(); + $phpPath = $finder->find(); + if (!$phpPath) { + throw new \RuntimeException('Failed to locate PHP binary to execute '.$scriptName); + } + + $memoryFlag = ' -d memory_limit='.ini_get('memory_limit'); + + return ProcessExecutor::escape($phpPath) . $memoryFlag; + } + /** * @param string $className * @param string $methodName