Exemple #1
0
 /**
  * Build a Process to run tivodecode decoding a file with a MAK
  *
  * @param string $mak    TiVo's Media Access Key
  * @param string $input  Where the encoded TiVo file is
  * @param string $output Where the decoded MPEG file goes
  *
  * @return Process
  */
 protected function buildProcess($mak, $input, $output)
 {
     $this->builder->setPrefix('/usr/local/bin/tivodecode');
     $this->builder->setArguments([$input, '--mak=' . $mak, '--no-verify', '--out=' . $output]);
     $this->builder->setTimeout(null);
     return $this->builder->getProcess();
 }
Exemple #2
0
 /**
  * Build a Process to run avahi-browse looking for TiVo on TCP
  *
  * @return Process
  */
 protected function buildProcess()
 {
     $this->builder->setPrefix('avahi-browse');
     $this->builder->setArguments(['--ignore-local', '--resolve', '--terminate', '_tivo-videos._tcp']);
     $this->builder->setTimeout(60);
     return $this->builder->getProcess();
 }
 public function testNullTimeout()
 {
     $pb = new ProcessBuilder();
     $pb->setTimeout(10);
     $pb->setTimeout(null);
     $r = new \ReflectionObject($pb);
     $p = $r->getProperty('timeout');
     $p->setAccessible(true);
     $this->assertNull($p->getValue($pb));
 }
 public function __construct(LoggerInterface $logger = null, ProcessBuilder $builder, MessageProviderInterface $provider, MessagePublisherInterface $publisher, $commandPath, $environment, $verbosity = OutputInterface::VERBOSITY_NORMAL)
 {
     $this->logger = $logger ?: new NullLogger();
     $this->builder = $builder;
     $this->provider = $provider;
     $this->publisher = $publisher;
     $this->verbosity = $verbosity;
     $this->commandPath = $commandPath;
     $this->environment = $environment;
     $this->builder->setTimeout(null);
 }
 /**
  * {@inheritdoc}
  */
 public function fetch($scratchDir, LoggerInterface $logger)
 {
     $logger->info(sprintf('Running mysqldump for: %s', $this->database));
     $processBuilder = new ProcessBuilder();
     $processBuilder->setTimeout($this->timeout);
     if (null !== $this->sshHost && null !== $this->sshUser) {
         $processBuilder->add('ssh');
         $processBuilder->add(sprintf('%s@%s', $this->sshUser, $this->sshHost));
         $processBuilder->add(sprintf('-p %s', $this->sshPort));
     }
     $processBuilder->add('mysqldump');
     $processBuilder->add(sprintf('-u%s', $this->user));
     if (null !== $this->host) {
         $processBuilder->add(sprintf('-h%s', $this->host));
     }
     if (null !== $this->password) {
         $processBuilder->add(sprintf('-p%s', $this->password));
     }
     $processBuilder->add($this->database);
     $process = $processBuilder->getProcess();
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     file_put_contents(sprintf('%s/%s.sql', $scratchDir, $this->database), $process->getOutput());
 }
 /**
  * @throws \RuntimeException if server could not be started within $this->timeout seconds
  */
 public function start()
 {
     if ($this->isRunning()) {
         return;
     }
     $processBuilder = new ProcessBuilder(['/usr/bin/php', '-S', "{$this->host}:{$this->port}", '-t', $this->webRoot]);
     $processBuilder->setTimeout(10);
     $this->serverProcess = $processBuilder->getProcess();
     $this->serverProcess->start();
     // server needs some time to boot up
     $serverIsBooting = true;
     $timeoutAt = time() + $this->timeout;
     while ($this->serverProcess->isRunning() && $serverIsBooting) {
         try {
             $socket = fsockopen($this->host, $this->port);
             if ($socket) {
                 $serverIsBooting = false;
             }
         } catch (\Exception $ex) {
             // server not ready
             if ($timeoutAt < time()) {
                 throw new \RuntimeException("Could not start Web Server [host = {$this->host}; port = {$this->port}; web root = {$this->webRoot}]");
             }
         }
         usleep(10);
     }
 }
 /**
  * Creates a new process builder.
  *
  * @param array $arguments An optional array of arguments
  *
  * @return ProcessBuilder A new process builder
  */
 protected function createProcessBuilder(array $arguments = array())
 {
     $pb = new ProcessBuilder($arguments);
     if (null !== $this->timeout) {
         $pb->setTimeout($this->timeout);
     }
     return $pb;
 }
 /**
  * @inheritdoc
  */
 public function setTimeout($timeout)
 {
     $this->timeout = $timeout;
     if (!static::$emulateSfLTS) {
         $this->builder->setTimeout($this->timeout);
     }
     return $this;
 }
 /**
  * Launches a command as a separate process.
  *
  * The '--process-timeout' parameter can be used to set the process timeout
  * in seconds. Default timeout is 300 seconds.
  * If '--ignore-errors' parameter is specified any errors are ignored;
  * otherwise, an exception is raises if an error happened.
  * If '--disable-cache-sync' parameter is specified a synchronization of caches between current
  * process and its child processes are disabled.
  *
  * @param string               $command
  * @param array                $params
  * @param LoggerInterface|null $logger
  *
  * @return integer The exit status code
  *
  * @throws \RuntimeException if command failed and '--ignore-errors' parameter is not specified
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function runCommand($command, $params = [], LoggerInterface $logger = null)
 {
     $params = array_merge(['command' => $command], $params);
     if ($this->env && $this->env !== 'dev') {
         $params['--env'] = $this->env;
     }
     $ignoreErrors = false;
     if (array_key_exists('--ignore-errors', $params)) {
         $ignoreErrors = true;
         unset($params['--ignore-errors']);
     }
     $pb = new ProcessBuilder();
     $pb->add($this->getPhp())->add($this->consoleCmdPath);
     if (array_key_exists('--process-timeout', $params)) {
         $pb->setTimeout($params['--process-timeout']);
         unset($params['--process-timeout']);
     } else {
         $pb->setTimeout($this->defaultTimeout);
     }
     $disableCacheSync = false;
     if (array_key_exists('--disable-cache-sync', $params)) {
         $disableCacheSync = $params['--disable-cache-sync'];
         unset($params['--disable-cache-sync']);
     }
     foreach ($params as $name => $val) {
         $this->processParameter($pb, $name, $val);
     }
     $process = $pb->inheritEnvironmentVariables(true)->getProcess();
     if (!$logger) {
         $logger = new NullLogger();
     }
     $exitCode = $process->run(function ($type, $data) use($logger) {
         if ($type === Process::ERR) {
             $logger->error($data);
         } else {
             $logger->notice($data);
         }
     });
     // synchronize all data caches
     if ($this->dataCacheManager && !$disableCacheSync) {
         $this->dataCacheManager->sync();
     }
     $this->processResult($exitCode, $ignoreErrors, $logger);
     return $exitCode;
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Server running on <info>http://localhost:8000/</info>');
     $builder = new ProcessBuilder([PHP_BINARY, '-S', 'localhost:8000', '-t', 'web/', sprintf('web/%s.php', $input->getOption('env'))]);
     $builder->setTimeout(null);
     $builder->getProcess()->run(function ($type, $buffer) use($output) {
         $output->write($buffer);
     });
 }
Exemple #11
0
 /**
  * @param array $commands
  * @param \Hshn\NpmBundle\Npm\ConfigurationInterface $configuration
  * @return \Symfony\Component\Process\Process
  */
 private function createProcess(array $commands, ConfigurationInterface $configuration)
 {
     $builder = new ProcessBuilder([$this->binPath]);
     $builder->setWorkingDirectory($configuration->getDirectory());
     $builder->setTimeout(600);
     foreach ($commands as $command) {
         $builder->add($command);
     }
     return $builder->getProcess();
 }
Exemple #12
0
 private function startWebServer(InputInterface $input, OutputInterface $output, $targetDirectory)
 {
     $builder = new ProcessBuilder([PHP_BINARY, '-S', $input->getArgument('address')]);
     $builder->setWorkingDirectory($targetDirectory);
     $builder->setTimeout(null);
     $process = $builder->getProcess();
     $process->start();
     $output->writeln(sprintf("Server running on <comment>%s</comment>", $input->getArgument('address')));
     return $process;
 }
 /**
  * {@inheritdoc}
  */
 public function getProcessBuilder(array $arguments, $timeout = self::DEFAULT_PROCESS_TIMEOUT)
 {
     $builder = new ProcessBuilder();
     $builder->setPrefix($this->getPhpBinary());
     $builder->setWorkingDirectory($this->getCwd());
     $builder->setArguments($arguments);
     $builder->setTimeout($timeout);
     $builder->inheritEnvironmentVariables(true);
     return $builder;
 }
 /**
  * Launches a command.
  * If '--process-isolation' parameter is specified the command will be launched as a separate process.
  * In this case you can parameter '--process-timeout' to set the process timeout
  * in seconds. Default timeout is 60 seconds.
  * If '--ignore-errors' parameter is specified any errors are ignored;
  * otherwise, an exception is raises if an error happened.
  *
  * @param string $command
  * @param array  $params
  * @return CommandExecutor
  * @throws \RuntimeException if command failed and '--ignore-errors' parameter is not specified
  */
 public function runCommand($command, $params = array())
 {
     $params = array_merge(array('command' => $command, '--no-debug' => true), $params);
     if ($this->env && $this->env !== 'dev') {
         $params['--env'] = $this->env;
     }
     $ignoreErrors = false;
     if (array_key_exists('--ignore-errors', $params)) {
         $ignoreErrors = true;
         unset($params['--ignore-errors']);
     }
     if (array_key_exists('--process-isolation', $params)) {
         unset($params['--process-isolation']);
         $phpFinder = new PhpExecutableFinder();
         $php = $phpFinder->find();
         $pb = new ProcessBuilder();
         $pb->add($php)->add($_SERVER['argv'][0]);
         if (array_key_exists('--process-timeout', $params)) {
             $pb->setTimeout($params['--process-timeout']);
             unset($params['--process-timeout']);
         }
         foreach ($params as $param => $val) {
             if ($param && '-' === $param[0]) {
                 if ($val === true) {
                     $pb->add($param);
                 } elseif (is_array($val)) {
                     foreach ($val as $value) {
                         $pb->add($param . '=' . $value);
                     }
                 } else {
                     $pb->add($param . '=' . $val);
                 }
             } else {
                 $pb->add($val);
             }
         }
         $process = $pb->inheritEnvironmentVariables(true)->getProcess();
         $output = $this->output;
         $process->run(function ($type, $data) use($output) {
             $output->write($data);
         });
         $ret = $process->getExitCode();
     } else {
         $this->application->setAutoExit(false);
         $ret = $this->application->run(new ArrayInput($params), $this->output);
     }
     if (0 !== $ret) {
         if ($ignoreErrors) {
             $this->output->writeln(sprintf('<error>The command terminated with an error code: %u.</error>', $ret));
         } else {
             throw new \RuntimeException(sprintf('The command terminated with an error status: %u.', $ret));
         }
     }
     return $this;
 }
Exemple #15
0
 /**
  * Launches a command.
  * If '--process-isolation' parameter is specified the command will be launched as a separate process.
  * In this case you can parameter '--process-timeout' to set the process timeout
  * in seconds. Default timeout is 300 seconds.
  * If '--ignore-errors' parameter is specified any errors are ignored;
  * otherwise, an exception is raises if an error happened.
  *
  * @param string $command
  * @param array  $params
  * @return CommandExecutor
  * @throws \RuntimeException if command failed and '--ignore-errors' parameter is not specified
  */
 public function runCommand($command, $params = [])
 {
     $params = array_merge(['command' => $command], $params);
     if ($this->env && $this->env !== 'dev') {
         $params['--env'] = $this->env;
     }
     $ignoreErrors = false;
     if (array_key_exists('--ignore-errors', $params)) {
         $ignoreErrors = true;
         unset($params['--ignore-errors']);
     }
     if (array_key_exists('--process-isolation', $params)) {
         unset($params['--process-isolation']);
         $pb = new ProcessBuilder();
         $pb->add($this->getPhp())->add($_SERVER['argv'][0]);
         if (array_key_exists('--process-timeout', $params)) {
             $pb->setTimeout($params['--process-timeout']);
             unset($params['--process-timeout']);
         } else {
             $pb->setTimeout($this->defaultTimeout);
         }
         foreach ($params as $name => $val) {
             $this->processParameter($pb, $name, $val);
         }
         $process = $pb->inheritEnvironmentVariables(true)->getProcess();
         $output = $this->output;
         $process->run(function ($type, $data) use($output) {
             $output->write($data);
         });
         $this->lastCommandExitCode = $process->getExitCode();
         // synchronize all data caches
         if ($this->dataCacheManager) {
             $this->dataCacheManager->sync();
         }
     } else {
         $this->application->setAutoExit(false);
         $this->lastCommandExitCode = $this->application->run(new ArrayInput($params), $this->output);
     }
     $this->processResult($ignoreErrors);
     return $this;
 }
Exemple #16
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln(sprintf("Server running on <info>http://%s</info>\n", $input->getArgument('address')));
     $builder = new ProcessBuilder(array(PHP_BINARY, '-S', $input->getArgument('address')));
     $builder->setWorkingDirectory($input->getOption('web-dir'));
     $builder->setTimeout(null);
     $builder->getProcess()->mustRun(function ($type, $buffer) use($output) {
         if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
             $output->write($buffer);
         }
     });
 }
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln(sprintf("Server running on <info>%s</info>\n", $input->getArgument('address')));
     $builder = new ProcessBuilder(array(PHP_BINARY, '-S', $input->getArgument('address'), __DIR__ . '/../../../src/router.php'));
     $builder->setWorkingDirectory($input->getOption('docroot'));
     $builder->setTimeout(null);
     $builder->getProcess()->run(function ($type, $buffer) use($output) {
         if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) {
             $output->write($buffer);
         }
     });
 }
 public function startServer()
 {
     $finder = new PhpExecutableFinder();
     if (false === ($binary = $finder->find())) {
         throw new \RuntimeException('Unable to find PHP binary to run server.');
     }
     $builder = new ProcessBuilder(['exec', $binary, '-S', $this->address, realpath(__DIR__ . '/../Resource/server.php')]);
     $builder->setWorkingDirectory(realpath(__DIR__ . '/../Resource'));
     $builder->setTimeout(null);
     $this->process = $builder->getProcess();
     $this->process->start();
     $this->waitServer();
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $router = $input->getOption('router') ?: $this->getContainer()->get('kernel')->locateResource('@FrameworkBundle/Resources/config/router.php');
     $output->writeln(sprintf("Server running on <info>%s</info>\n", $input->getArgument('address')));
     $builder = new ProcessBuilder(array(PHP_BINARY, '-S', $input->getArgument('address'), $router));
     $builder->setWorkingDirectory($input->getOption('docroot'));
     $builder->setTimeout(null);
     $builder->getProcess()->run(function ($type, $buffer) use($output) {
         if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) {
             $output->write($buffer);
         }
     });
 }
 public function filterDump(AssetInterface $asset)
 {
     $is64bit = PHP_INT_SIZE === 8;
     $cleanup = array();
     $pb = new ProcessBuilder(array_merge(array($this->javaPath), $is64bit ? array('-server', '-XX:+TieredCompilation') : array('-client', '-d32'), array('-jar', $this->jarPath)));
     if (null !== $this->timeout) {
         $pb->setTimeout($this->timeout);
     }
     if (null !== $this->compilationLevel) {
         $pb->add('--compilation_level')->add($this->compilationLevel);
     }
     if (null !== $this->jsExterns) {
         $cleanup[] = $externs = tempnam(sys_get_temp_dir(), 'assetic_google_closure_compiler');
         file_put_contents($externs, $this->jsExterns);
         $pb->add('--externs')->add($externs);
     }
     if (null !== $this->externsUrl) {
         $cleanup[] = $externs = tempnam(sys_get_temp_dir(), 'assetic_google_closure_compiler');
         file_put_contents($externs, file_get_contents($this->externsUrl));
         $pb->add('--externs')->add($externs);
     }
     if (null !== $this->excludeDefaultExterns) {
         $pb->add('--use_only_custom_externs');
     }
     if (null !== $this->formatting) {
         $pb->add('--formatting')->add($this->formatting);
     }
     if (null !== $this->useClosureLibrary) {
         $pb->add('--manage_closure_dependencies');
     }
     if (null !== $this->warningLevel) {
         $pb->add('--warning_level')->add($this->warningLevel);
     }
     if (null !== $this->language) {
         $pb->add('--language_in')->add($this->language);
     }
     if (null !== $this->flagFile) {
         $pb->add('--flagfile')->add($this->flagFile);
     }
     $pb->add('--js')->add($cleanup[] = $input = tempnam(sys_get_temp_dir(), 'assetic_google_closure_compiler'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $code = $proc->run();
     array_map('unlink', $cleanup);
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
Exemple #21
0
 /**
  * Запустить сервер
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param string $targetDirectory
  * @return \Symfony\Component\Process\Process
  */
 private function startWebServer(InputInterface $input, OutputInterface $output, $targetDirectory)
 {
     $manifestPath = getcwd() . '/' . $input->getArgument('manifest');
     $manifest = new \Dmitrynaum\SAM\Component\Manifest($manifestPath);
     $address = $manifest->getServerAddress();
     $builder = new ProcessBuilder([PHP_BINARY, '-S', $address, 'server.php']);
     $builder->setWorkingDirectory($targetDirectory);
     $builder->setEnv('projectDir', getcwd());
     $builder->setEnv('manifestPath', $manifestPath);
     $builder->setTimeout(null);
     $process = $builder->getProcess();
     $process->start();
     $output->writeln(sprintf('Server running on <comment>%s</comment>', $address));
     return $process;
 }
Exemple #22
0
 /**
  * {@inheritDoc}
  */
 public function run(OutputInterface $output)
 {
     $arguments = $this->resolveProcessArgs();
     $builder = new ProcessBuilder($arguments);
     if (null !== ($dispatcher = $this->getEventDispatcher())) {
         $event = new PreExecuteEvent($this, $builder);
         $dispatcher->dispatch(Event::PRE_EXECUTE, $event);
         if ($event->isPropagationStopped()) {
             return true;
         }
     }
     if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERY_VERBOSE) {
         $output->writeln(sprintf('        // Setting timeout for %d seconds.', $this->getParameter('timeout')));
     }
     $builder->setTimeout($this->getParameter('timeout') !== 0 ? $this->getParameter('timeout') : null);
     if ($this->hasParameter('cwd')) {
         $builder->setWorkingDirectory($this->getParameter('cwd'));
     }
     $process = $builder->getProcess();
     if (get_class($this) === 'Bldr\\Block\\Execute\\Task\\ExecuteTask') {
         $output->writeln(['', sprintf('    <info>[%s]</info> - <comment>Starting</comment>', $this->getName()), '']);
     }
     if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE || $this->getParameter('dry_run')) {
         $output->writeln('        // ' . $process->getCommandLine());
     }
     if ($this->getParameter('dry_run')) {
         return true;
     }
     if ($this->hasParameter('output')) {
         $append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w';
         $stream = fopen($this->getParameter('output'), $append);
         $output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true);
     }
     $process->start(function ($type, $buffer) use($output) {
         $output->write("\r        " . str_replace("\n", "\n        ", $buffer));
     });
     while ($process->isRunning()) {
     }
     if (null !== $dispatcher) {
         $event = new PostExecuteEvent($this, $process);
         $dispatcher->dispatch(Event::POST_EXECUTE, $event);
     }
     if (!in_array($process->getExitCode(), $this->getParameter('successCodes'))) {
         throw new TaskRuntimeException($this->getName(), $process->getErrorOutput());
     }
 }
Exemple #23
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $env = $this->getContainer()->getParameter('kernel.environment');
     if ('prod' === $env) {
         $output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>');
     }
     $router = $input->getOption('router') ?: $this->getContainer()->get('kernel')->locateResource(sprintf('@FrameworkBundle/Resources/config/router_%s.php', $env));
     $output->writeln(sprintf("Server running on <info>%s</info>\n", $input->getArgument('address')));
     $builder = new ProcessBuilder(array(PHP_BINARY, '-S', $input->getArgument('address'), $router));
     $builder->setWorkingDirectory($input->getOption('docroot'));
     $builder->setTimeout(null);
     $builder->getProcess()->run(function ($type, $buffer) use($output) {
         if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
             $output->write($buffer);
         }
     });
 }
 public function compileAndWatch(Closure $callback = null)
 {
     $config = $this->webpackConfigManager->dump();
     $processBuilder = new ProcessBuilder();
     $processBuilder->setArguments(array_merge($this->devServerExecutable, array('--config', $config->getConfigPath()), $this->devServerArguments));
     $processBuilder->setWorkingDirectory($this->workingDirectory);
     $processBuilder->setTimeout(0);
     $prefix = DIRECTORY_SEPARATOR === '\\' ? array() : array('exec');
     $ttyPrefix = array_merge($prefix, $this->devServerTtyPrefix);
     $process = $this->buildProcess($processBuilder, $prefix, $ttyPrefix);
     $this->addEnvironment($process, 'WEBPACK_MODE=watch');
     // remove manifest file if exists - keep sure we create new one
     if (file_exists($this->manifestPath)) {
         $this->logger->info('Deleting manifest file', array($this->manifestPath));
         unlink($this->manifestPath);
     }
     $that = $this;
     $logger = $this->logger;
     $processCallback = function ($type, $buffer) use($that, $callback, $logger) {
         $that->saveManifest(false);
         $logger->info('Processing callback from process', array($type, $buffer));
         if ($callback !== null) {
             $callback($type, $buffer);
         }
     };
     $this->logger->info('Starting process', array($process->getCommandLine()));
     $process->start($processCallback);
     while (true) {
         sleep(1);
         $this->logger->debug('Dumping webpack configuration');
         $config = $this->webpackConfigManager->dump($config);
         if ($config->wasFileDumped()) {
             $this->logger->info('File was dumped (configuration changed) - restarting process', $config->getEntryPoints());
             $process->stop();
             $process = $process->restart($processCallback);
         } else {
             if (!$process->isRunning()) {
                 $this->logger->info('Process has shut down - returning');
                 return;
             }
             $process->getOutput();
             // try to save the manifest - output callback is not called in dashboard mode
             $that->saveManifest(false);
         }
     }
 }
Exemple #25
0
 /**
  * @param SymfonyStyle $io
  * @param string       $address
  * @param string       $webDir
  * @param string       $router
  *
  * @return null|\Symfony\Component\Process\Process
  */
 protected function createServerProcess(SymfonyStyle $io, $address, $webDir, $router)
 {
     if (!file_exists($router)) {
         $io->error(sprintf('The router script "%s" does not exist', $router));
         return null;
     }
     $finder = new PhpExecutableFinder();
     if (($binary = $finder->find()) === false) {
         $io->error('Unable to find PHP binary to run server.');
         return null;
     }
     $builder = new ProcessBuilder([$binary, '-S', $address, '-t', $webDir, $router]);
     $builder->setTimeout(null);
     if ($io->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) {
         $builder->disableOutput();
     }
     return $builder->getProcess();
 }
Exemple #26
0
 public static function checkCanCreatePhar()
 {
     if (!ini_get('phar.readonly')) {
         return;
     }
     $php = $_SERVER['_'];
     if (preg_match("@/php[0-9\\.]*\$@", $php)) {
         $argv = array_merge([$php, '-d', 'phar.readonly=off'], $GLOBALS['argv']);
     } else {
         $argv = array_merge(['/usr/bin/env', 'php', '-d', 'phar.readonly=off'], $GLOBALS['argv']);
     }
     $builder = new ProcessBuilder($argv);
     $builder->setTimeout(300);
     $builder->getProcess()->run(function ($type, $buffer) {
         echo $buffer;
     });
     exit;
     /* Die! */
 }
 protected function getProcessBuilder($cmd, array $extras = array(), $input = null)
 {
     $builder = new ProcessBuilder();
     $builder->add($cmd);
     $builder->setTimeout($this->options['process-timeout']);
     foreach ($this->arguments as $argument) {
         try {
             $builder->add($this->getFormattedParameter($argument, $this->getArgument($argument)));
         } catch (\InvalidArgumentException $ex) {
             //nothing here
         }
     }
     foreach ($extras as $key => $value) {
         try {
             $builder->add($this->getFormattedParameter($key, $value));
         } catch (\InvalidArgumentException $ex) {
             //nothing here
         }
     }
     if (!is_null($input)) {
         $builder->setInput($input);
     }
     return $builder;
 }
 /**
  * Sets the process timeout.
  *
  * To disable the timeout, set this value to null.
  *
  * @param float|null $timeout
  *
  * @return ProcessBuilderProxyInterface
  *
  * @throws InvalidArgumentException
  */
 public function setTimeout(float $timeout) : ProcessBuilderProxyInterface
 {
     $this->timeout = $timeout;
     $this->processBuilder->setTimeout($timeout);
     return $this;
 }
 /**
  * Launches a command.
  * If '--process-isolation' parameter is specified the command will be launched as a separate process.
  * In this case you can parameter '--process-timeout' to set the process timeout
  * in seconds. Default timeout is 60 seconds.
  *
  * @param string          $command
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @param array           $params
  * @return InstallCommand
  */
 protected function runCommand($command, InputInterface $input, OutputInterface $output, $params = array())
 {
     $params = array_merge(array('command' => $command, '--no-debug' => true), $params);
     if ($input->hasOption('env') && $input->getOption('env') !== 'dev') {
         $params['--env'] = $input->getOption('env');
     }
     if (array_key_exists('--process-isolation', $params)) {
         unset($params['--process-isolation']);
         $phpFinder = new PhpExecutableFinder();
         $php = $phpFinder->find();
         $pb = new ProcessBuilder();
         $pb->add($php)->add($_SERVER['argv'][0]);
         if (array_key_exists('--process-timeout', $params)) {
             $pb->setTimeout($params['--process-timeout']);
             unset($params['--process-timeout']);
         }
         foreach ($params as $param => $val) {
             if ($param && '-' === $param[0]) {
                 if ($val === true) {
                     $pb->add($param);
                 } else {
                     $pb->add($param . '=' . $val);
                 }
             } else {
                 $pb->add($val);
             }
         }
         $process = $pb->inheritEnvironmentVariables(true)->getProcess();
         $process->run(function ($type, $data) use($output) {
             $output->write($data);
         });
         $ret = $process->getExitCode();
     } else {
         $this->getApplication()->setAutoExit(false);
         $ret = $this->getApplication()->run(new ArrayInput($params), $output);
     }
     if (0 !== $ret) {
         $output->writeln(sprintf('<error>The command terminated with an error status (%s)</error>', $ret));
     }
     return $this;
 }
Exemple #30
0
 /**
  * @return bool
  */
 private function unitTests()
 {
     $processBuilder = new ProcessBuilder(array('php', 'bin/atoum'));
     $processBuilder->setWorkingDirectory(getcwd());
     $processBuilder->setTimeout(null);
     $phpunit = $processBuilder->getProcess();
     $phpunit->run(function ($type, $buffer) {
         $this->output->write($buffer);
     });
     return $phpunit->isSuccessful();
 }