Added support for change the process timeout
parent
b8f200b0f2
commit
56c0e511da
|
@ -15,6 +15,7 @@ namespace Composer;
|
|||
use Composer\Json\JsonFile;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Repository\RepositoryManager;
|
||||
use Composer\Util\ProcessExecutor;
|
||||
|
||||
/**
|
||||
* Creates an configured instance of composer.
|
||||
|
@ -67,6 +68,11 @@ class Factory
|
|||
}
|
||||
$binDir = getenv('COMPOSER_BIN_DIR') ?: $packageConfig['config']['bin-dir'];
|
||||
|
||||
// setup process timeout
|
||||
if (false !== getenv('COMPOSER_PROCESS_TIMEOUT')) {
|
||||
ProcessExecutor::setTimeout((int) getenv('COMPOSER_PROCESS_TIMEOUT'));
|
||||
}
|
||||
|
||||
// initialize repository manager
|
||||
$rm = $this->createRepositoryManager($io);
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ use Symfony\Component\Process\Process;
|
|||
*/
|
||||
class ProcessExecutor
|
||||
{
|
||||
static protected $timeout = 60;
|
||||
|
||||
/**
|
||||
* runs a process on the commandline
|
||||
*
|
||||
|
@ -29,7 +31,7 @@ class ProcessExecutor
|
|||
public function execute($command, &$output = null)
|
||||
{
|
||||
$captureOutput = count(func_get_args()) > 1;
|
||||
$process = new Process($command);
|
||||
$process = new Process($command, null, null, null, static::getTimeout());
|
||||
$process->run(function($type, $buffer) use ($captureOutput) {
|
||||
if ($captureOutput) {
|
||||
return;
|
||||
|
@ -49,4 +51,14 @@ class ProcessExecutor
|
|||
{
|
||||
return ((string) $output === '') ? array() : preg_split('{\r?\n}', $output);
|
||||
}
|
||||
}
|
||||
|
||||
static public function getTimeout()
|
||||
{
|
||||
return static::$timeout;
|
||||
}
|
||||
|
||||
static public function setTimeout($timeout)
|
||||
{
|
||||
static::$timeout = $timeout;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,14 @@ class ProcessExecutorTest extends TestCase
|
|||
$this->assertEquals("foo".PHP_EOL, $output);
|
||||
}
|
||||
|
||||
public function testTimeout()
|
||||
{
|
||||
ProcessExecutor::setTimeout(1);
|
||||
$process = new ProcessExecutor;
|
||||
$this->assertEquals(1, $process->getTimeout());
|
||||
ProcessExecutor::setTimeout(60);
|
||||
}
|
||||
|
||||
public function testSplitLines()
|
||||
{
|
||||
$process = new ProcessExecutor;
|
||||
|
|
Loading…
Reference in New Issue