Merge pull request #345 from hason/process
Added support for change the process timeoutpull/343/merge
commit
62335e9fb7
|
@ -15,6 +15,7 @@ namespace Composer;
|
||||||
use Composer\Json\JsonFile;
|
use Composer\Json\JsonFile;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Repository\RepositoryManager;
|
use Composer\Repository\RepositoryManager;
|
||||||
|
use Composer\Util\ProcessExecutor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an configured instance of composer.
|
* Creates an configured instance of composer.
|
||||||
|
@ -67,6 +68,11 @@ class Factory
|
||||||
}
|
}
|
||||||
$binDir = getenv('COMPOSER_BIN_DIR') ?: $packageConfig['config']['bin-dir'];
|
$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
|
// initialize repository manager
|
||||||
$rm = $this->createRepositoryManager($io);
|
$rm = $this->createRepositoryManager($io);
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@ use Symfony\Component\Process\Process;
|
||||||
*/
|
*/
|
||||||
class ProcessExecutor
|
class ProcessExecutor
|
||||||
{
|
{
|
||||||
|
static protected $timeout = 60;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* runs a process on the commandline
|
* runs a process on the commandline
|
||||||
*
|
*
|
||||||
|
@ -29,7 +31,7 @@ class ProcessExecutor
|
||||||
public function execute($command, &$output = null)
|
public function execute($command, &$output = null)
|
||||||
{
|
{
|
||||||
$captureOutput = count(func_get_args()) > 1;
|
$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) {
|
$process->run(function($type, $buffer) use ($captureOutput) {
|
||||||
if ($captureOutput) {
|
if ($captureOutput) {
|
||||||
return;
|
return;
|
||||||
|
@ -49,4 +51,14 @@ class ProcessExecutor
|
||||||
{
|
{
|
||||||
return ((string) $output === '') ? array() : preg_split('{\r?\n}', $output);
|
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);
|
$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()
|
public function testSplitLines()
|
||||||
{
|
{
|
||||||
$process = new ProcessExecutor;
|
$process = new ProcessExecutor;
|
||||||
|
|
Loading…
Reference in New Issue