setTimeout() public method

To disable the timeout, set this value to null.
public setTimeout ( integer | float | null $timeout ) : self
$timeout integer | float | null The timeout in seconds
return self The current Process instance
示例#1
1
 private static function setUpPhpServer()
 {
     self::$process = new Process('php -S [::1]:8999', __DIR__ . '/../../Resources/Scripts');
     self::$process->setTimeout(1);
     self::$process->start();
     usleep(100000);
 }
示例#2
0
 /**
  * Starts the internal PHP server using excerpts from my (awesome)
  * travel blog as the docroot.
  */
 public function startDemoServer()
 {
     $docRoot = realpath(__DIR__ . '/../../demo/mike-on-a-bike.com');
     $this->demoServerProcess = new Process('php -S ' . self::HOST . ' -t ' . $docRoot);
     $this->demoServerProcess->setTimeout(3600);
     $this->demoServerProcess->start();
 }
示例#3
0
 /**
  * Running a command on local machine.
  * @param  string $commandline
  * @param  array  $options
  * @return ProcessResult
  */
 public function runLocally($commandline, $options = array())
 {
     if (is_array($commandline)) {
         $os = php_uname('s');
         if (preg_match('/Windows/i', $os)) {
             $commandline = implode(" & ", $commandline);
         } else {
             $commandline = implode(" && ", $commandline);
         }
     }
     $this->runtimeTask->getOutput()->writeln($this->getLocalInfoPrefix() . "<info>Run: </info>{$commandline}");
     $realCommand = $this->compileRealCommand($commandline, $options, TRUE);
     if ($this->runtimeTask->getOutput()->isVeryVerbose()) {
         $this->runtimeTask->getOutput()->writeln($this->getLocalInfoPrefix() . "<info>Real command: </info>{$realCommand}");
     }
     $self = $this;
     $symfonyProcess = new SymfonyProcess($realCommand);
     if (isset($options["timeout"])) {
         $symfonyProcess->setTimeout($options["timeout"]);
     } else {
         $symfonyProcess->setTimeout(null);
     }
     $resultContent = null;
     $returnCode = $symfonyProcess->run(function ($type, $buffer) use($self, &$resultContent) {
         $self->getRuntimeTask()->getOutput()->write($buffer);
         $resultContent .= $buffer;
     });
     return new ProcessResult($returnCode, $resultContent);
 }
示例#4
0
 public function testNullTimeout()
 {
     $p = new Process('');
     $p->setTimeout(10);
     $p->setTimeout(null);
     $this->assertNull($p->getTimeout());
 }
 /**
  * Executes the command $cmd
  *
  * @param string $cmd
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param bool $silent
  * @param bool $tty
  * @return string|void
  */
 public function exec($cmd, $output = null, $silent = FALSE, $tty = FALSE)
 {
     $process = new Process($cmd);
     if ($tty) {
         $process->setTty(TRUE);
     }
     $process->setTimeout(null);
     if (!$silent && $output) {
         $output->writeln($this->messageService->lightGray('-------------------------------------------------'));
         $output->writeln($this->messageService->lightGray('Executing: ' . $cmd));
         $messageService = $this->messageService;
         $process->setTimeout(3600);
         $process->start();
         $process->wait(function ($type, $buffer) use($output, $messageService) {
             if (Process::ERR === $type) {
                 $output->writeln($messageService->red('----> ERROR START'));
                 $output->write($messageService->red('----> ' . $buffer));
                 $output->writeln($messageService->red('----> ERROR END'));
             } else {
                 $output->write($messageService->green($buffer));
             }
         });
     } else {
         $process->run();
     }
     return $process->getOutput();
 }
示例#6
0
 /**
  * Runner constructor.
  *
  * @param string $input
  * @param array $tokens
  * @param bool $script_source
  */
 public function __construct($input, array $tokens = [], $script_source = self::TEMPLATE_INPUT)
 {
     $this->process = new Process('');
     $this->process->setTimeout(null);
     if ($script_source === self::TEMPLATE_INPUT) {
         $this->script = with(new Parser())->parseFile($input, $tokens);
     } else {
         $this->script = with(new Parser())->parseString($input, $tokens);
     }
 }
示例#7
0
 /**
  * @param $command
  * @throws ShellProcessFailed
  * @throws \Symfony\Component\Process\Exception\LogicException
  */
 public function process($command)
 {
     if (empty($command)) {
         return;
     }
     $this->process->setCommandLine($command);
     $this->process->setTimeout(null);
     $this->process->run();
     if (!$this->process->isSuccessful()) {
         throw new ShellProcessFailed($this->process->getErrorOutput());
     }
 }
 /**
  * {@inheritDoc}
  *
  * Starts the connection
  */
 public function _reconfigure($config = array())
 {
     parent::_reconfigure($config);
     if (!isset($this->config['username'])) {
         throw new \Exception("Sauce Connect Extension requires a username.");
     }
     if (!isset($this->config['accesskey'])) {
         throw new \Exception("Sauce Connect Extension requires a accesskey.");
     }
     $connect = __DIR__ . '/../../../bin/sauce_connect';
     if (!file_exists($connect)) {
         $connect = __DIR__ . '/../../../../bin/sauce_connect';
     }
     if (!file_exists($connect)) {
         throw new \Exception("Couldnt find the bin directory... Make sure its in ./bin or ./vendor/bin/");
     }
     $processBuilder = new ProcessBuilder([$connect]);
     $processBuilder->addEnvironmentVariables(['SAUCE_USERNAME' => $this->config['username'], 'SAUCE_ACCESS_KEY' => $this->config['accesskey']]);
     $timeout = isset($this->config['timeout']) ? $this->config['timeout'] : 60;
     $this->process = $processBuilder->getProcess();
     $this->process->setTimeout(0);
     $this->process->start(function ($type, $buffer) {
         $buffer = explode("\n", $buffer);
         foreach ($buffer as $line) {
             if (strpos($line, 'Press any key to see more output') === false) {
                 file_put_contents(codecept_output_dir() . 'sauce_connect.log', $line . "\n", FILE_APPEND);
             }
         }
     });
     $timer = 0;
     $connected = false;
     $this->writeln(["", "----------------------------------------------------------------------------", "Attempting to connect to SauceLabs. Waiting {$timeout} seconds."]);
     while ($this->process->isRunning() && $timer < $timeout) {
         $output = $this->process->getOutput();
         if (strpos($output, 'Connected! You may start your tests.') !== false) {
             $connected = true;
             break;
         }
         sleep(1);
         $timer++;
         if ($timer % 5 === 0) {
             $this->write('.');
         }
     }
     if (false === $connected) {
         $this->process->stop();
         throw new \Exception(sprintf("Could not start tunnel. Check %ssauce_connect.log for more information.", codecept_output_dir()));
     }
     $this->writeln(["", "Connected to SauceLabs", "----------------------------------------------------------------------------", ""]);
 }
示例#9
0
 public function execute()
 {
     $logger = $this->getRunConfig()->getLogger();
     $this->process = new Process($this->command);
     $logger->info('Start command:' . $this->command);
     $this->process->setTimeout($this->timeout);
     $this->process->setWorkingDirectory($this->getRunConfig()->getRepositoryDirectory());
     $this->process->run();
     $output = trim($this->process->getOutput());
     $logger->info($output);
     if (!$this->process->isSuccessful()) {
         $logger->emergency($this->process->getErrorOutput());
         throw new \RuntimeException('Command not successful:' . $this->command);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configCommand = $this->getApplication()->find('oro:requirejs:generate-config');
     $configCommand->run(new ArrayInput(['command' => 'oro:requirejs:generate-config']), $output);
     $webRoot = $this->getContainer()->getParameter('oro_require_js.web_root');
     $config = $this->getContainer()->getParameter('oro_require_js');
     $configProvider = $this->getContainer()->get('oro_requirejs_config_provider');
     $output->writeln('Generating require.js build config');
     $buildConfigContent = $configProvider->generateBuildConfig(self::MAIN_CONFIG_FILE_NAME);
     $buildConfigContent = '(' . json_encode($buildConfigContent) . ')';
     $buildConfigFilePath = $webRoot . DIRECTORY_SEPARATOR . self::BUILD_CONFIG_FILE_NAME;
     if (false === @file_put_contents($buildConfigFilePath, $buildConfigContent)) {
         throw new \RuntimeException('Unable to write file ' . $buildConfigFilePath);
     }
     if (isset($config['js_engine']) && $config['js_engine']) {
         $output->writeln('Running code optimizer');
         $command = $config['js_engine'] . ' ' . self::OPTIMIZER_FILE_PATH . ' -o ' . basename($buildConfigFilePath) . ' 1>&2';
         $process = new Process($command, $webRoot);
         $process->setTimeout($config['building_timeout']);
         $process->run();
         if (!$process->isSuccessful()) {
             throw new \RuntimeException($process->getErrorOutput());
         }
         $output->writeln('Cleaning up');
         if (false === @unlink($buildConfigFilePath)) {
             throw new \RuntimeException('Unable to remove file ' . $buildConfigFilePath);
         }
         $output->writeln(sprintf('<comment>%s</comment> <info>[file+]</info> %s', date('H:i:s'), realpath($webRoot . DIRECTORY_SEPARATOR . $config['build_path'])));
     }
 }
示例#11
0
 public function download($in_dir)
 {
     $repo = $in_dir . '/' . $this->package . ".git";
     if (is_dir($repo)) {
         return;
     }
     $cmd = 'git clone --mirror %s %s';
     $process = new Process(sprintf($cmd, $this->url, $repo));
     $process->setTimeout(3600);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \Exception($process->getErrorOutput());
     }
     $cmd = 'cd %s && git update-server-info -f';
     $process = new Process(sprintf($cmd, $repo));
     $process->setTimeout(3600);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \Exception($process->getErrorOutput());
     }
     $cmd = 'cd %s && git fsck';
     $process = new Process(sprintf($cmd, $repo));
     $process->setTimeout(3600);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \Exception($process->getErrorOutput());
     }
 }
 public function runCrons()
 {
     $entityManager = $this->managerRegistry->getManagerForClass('DspSoftsCronManagerBundle:CronTask');
     $cronTaskRepo = $entityManager->getRepository('DspSoftsCronManagerBundle:CronTask');
     $cronTasks = $cronTaskRepo->findCronsToLaunch();
     foreach ($cronTasks as $cronTask) {
         $run = true;
         if (!$cronTask->getRelaunch()) {
             $run = $this->planificationChecker->isExecutionDue($cronTask->getPlanification());
         }
         if ($run) {
             if ($this->logger !== null) {
                 $this->logger->info(sprintf('Running Cron Task <info>%s</info>', $cronTask->getName()));
             }
             $cli = 'exec ' . $this->kernelRootDir . DIRECTORY_SEPARATOR . 'console dsp:cron:runjob -c ' . $cronTask->getId() . ' &';
             if ($this->logger !== null) {
                 $this->logger->info(sprintf('Command line : <info>%s</info>', $cli));
             }
             $process = new Process($cli);
             $process->setTimeout(0);
             $process->start();
         } else {
             if ($this->logger !== null) {
                 $this->logger->info(sprintf('Skipping Cron Task <info>%s</info>', $cronTask->getName()));
             }
         }
     }
 }
示例#13
0
 /**
  * Starts the server
  *
  * @param array $options
  * @return void
  */
 public function start(array $options)
 {
     $verbose = isset($options['verbose']) && $options['verbose'];
     if ($this->checkServer()) {
         $this->output->writeln("<error>Queue Manager is already running.</error>");
         return;
     }
     if ($verbose) {
         $this->output->writeln("<info>Queue Manager is starting.</info>");
     }
     $phpFinder = new PhpExecutableFinder();
     $phpPath = $phpFinder->find();
     if ($options['daemon']) {
         $command = $phpPath . ' app/console naroga:queue:start ' . ($verbose ? '-v' : '') . ' &';
         $app = new Process($command);
         $app->setTimeout(0);
         $app->start();
         $pid = $app->getPid();
         $this->memcache->replace('queue.lock', $pid);
         if ($verbose) {
             $this->output->writeln('<info>Queue Manager started with PID = ' . ($pid + 1) . '.</info>');
         }
         return;
     }
     $this->registerListeners($verbose);
     if ($verbose) {
         $pid = $this->memcache->get('queue.lock');
         $this->output->writeln('<info>Queue Manager started with PID = ' . $pid . '.</info>');
     }
     $this->resetServerConfig($options);
     $this->processQueue($options);
 }
示例#14
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $commandLine = $input->getArgument('command-line');
     if (!$this->tryParseChunkSize($input->getOption('chunk-size'), $chunkSize)) {
         $output->writeln('<error>Chunk size must be number optionally suffixed with k or M.</error>');
         return 1;
     }
     $model = $this->model;
     if ($id = $input->getOption('instance')) {
         if (!($entity = $model->getById($id))) {
             $output->writeln('<error>Rixxi\\Process\\Entities\\IProcess instance does not exist.</error>');
             return 1;
         }
     } else {
         $entity = $model->create($commandLine);
     }
     $process = new Process($commandLine);
     $process->setTimeout(NULL);
     $process->setIdleTimeout(NULL);
     $exitCode = $process->run(function ($type, $output) use($entity, $model, $chunkSize) {
         if (strlen($output) > $chunkSize) {
             $output = str_split($output, $chunkSize);
         } else {
             $output = array($output);
         }
         foreach ($output as $chunk) {
             $model->append($entity, $chunk, $type === Process::ERR);
         }
     });
     $model->finish($entity, $exitCode);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->downloadConfiguration();
     $library = new GLibc();
     try {
         $this->download()->extract();
         $library->setEnv($this->env)->setProjectDir($this->baseDir)->initialize()->boot($input, $output);
         $configure = $this->projectDir . '/' . $library->configure();
         $this->projectDir = dirname($this->projectDir) . '/glibc-build';
         $this->fs->mkdir($this->projectDir);
         $this->output->write('    Building   :  ');
         $process = new Process($configure, $this->projectDir, $this->env->toArray());
         $process->setTimeout(0);
         $process->run();
         if ($process->isSuccessful()) {
             $process->setCommandLine('make -j4 && make -j4 install');
             $process->run();
         }
         if ($process->isSuccessful()) {
             $message = '<info>✔</info>';
         } else {
             $message = '<error>✕</error>';
         }
         $this->output->writeln($message);
     } catch (\Exception $e) {
         $this->cleanUp();
         throw $e;
     }
     $this->createConfiguration();
     $this->output->writeln(sprintf(" <info>%s</info>  Droidphp Installer <info>successfully configured</info> Now you can:\n" . "    * Run :\n" . "        1. Execute the <comment>%s build:components</comment> command.\n" . " To Build the project\n\n", defined('PHP_WINDOWS_VERSION_BUILD') ? 'OK' : '✔', basename($_SERVER['PHP_SELF'])));
 }
 public function testHttpDataDownloadUsingManyWorkers()
 {
     $filesystem = new Filesystem();
     $targetDirPath = TEMP_DIR . '/' . uniqid('test_http_download');
     $filesystem->mkdir($targetDirPath);
     $workersManager = new Process('php ' . BIN_DIR . '/spider.php worker:start-many -c 3');
     $workersManager->start();
     $this->assertTrue($workersManager->isRunning(), 'Workers Manager should be working');
     $collector = new Process('php ' . BIN_DIR . '/spider.php collector:start --target-folder=' . $targetDirPath);
     $collector->setIdleTimeout(10);
     // there should be an output/result at least once every 10 seconds
     $collector->start();
     $this->assertTrue($collector->isRunning(), 'Task Results Collector should be working');
     $taskLoader = new Process('php ' . BIN_DIR . '/spider.php tasks:load < ' . FIXTURES_DIR . '/uris.txt');
     $taskLoader->setTimeout(120);
     // 120 seconds is enough to complete the task
     $taskLoader->start();
     $this->assertTrue($taskLoader->isRunning(), 'Task Loader should be working');
     while ($taskLoader->isRunning()) {
         sleep(1);
         // waiting for process to complete
     }
     $taskLoaderOutput = $taskLoader->getOutput() . $taskLoader->getErrorOutput();
     $this->assertContains('Total count of Tasks put in the Queue: 10', $taskLoaderOutput, 'Task Loader should have loaded 10 Tasks');
     $this->assertContains('Waiting for acknowledgement from Task Result Collector', $taskLoaderOutput, 'Task Loader should have been waiting for Task Result Collector acknowledgement');
     $this->assertContains('Informing all workers to stop', $taskLoaderOutput, 'Task Loader should have inform Workers to stop');
     $fi = new \FilesystemIterator($targetDirPath, \FilesystemIterator::SKIP_DOTS);
     $this->assertEquals(10, iterator_count($fi), '10 Task Result Files expected');
 }
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $ext = pathinfo($input->getArgument('destination'), PATHINFO_EXTENSION);
     if (!in_array($ext, array('zip', 'gz'))) {
         throw new \RuntimeException(sprintf('Invalid filename: %s', $input->getArgument('destination')));
     }
     $fs = new Filesystem();
     if ($fs->exists($input->getArgument('destination'))) {
         $fs->remove($input->getArgument('destination'));
     }
     $tmpFile = sprintf("%s/composer_archive_%s.%s", sys_get_temp_dir(), sha1($input->getArgument('destination')), $ext);
     if ($fs->exists($tmpFile)) {
         $fs->remove($tmpFile);
     }
     if ($ext == 'gz') {
         $cmd = sprintf("cd %s && tar czf %s . %s", $input->getArgument('folder'), $tmpFile, $input->getOption('vcs') ? '' : '--exclude-vcs');
     } elseif ($ext == 'zip') {
         $cmd = sprintf("cd %s && zip -r -q %s . %s", $input->getArgument('folder'), $tmpFile, $input->getOption('vcs') ? '' : '-x *.git* *.svn*');
     }
     $output->writeln(sprintf("Creating temporary file: <info>%s</info>", $tmpFile));
     $output->writeln(sprintf("Starting command %s", $cmd));
     $process = new Process($cmd);
     $process->setTimeout(null);
     $process->run(function ($type, $data) use($output) {
         $output->write($data, false, OutputInterface::OUTPUT_PLAIN);
     });
     $fs->rename($tmpFile, $input->getArgument('destination'));
 }
示例#18
0
文件: Exec.php 项目: sliver/Robo
 public function run()
 {
     $command = $this->getCommand();
     $dir = $this->workingDirectory ? " in " . $this->workingDirectory : "";
     $this->printTaskInfo("running <info>{$command}</info>{$dir}");
     $this->process = new Process($command);
     $this->process->setTimeout($this->timeout);
     $this->process->setIdleTimeout($this->idleTimeout);
     $this->process->setWorkingDirectory($this->workingDirectory);
     if (!$this->background and !$this->isPrinted) {
         $this->process->run();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput());
     }
     if (!$this->background and $this->isPrinted) {
         $this->process->run(function ($type, $buffer) {
             Process::ERR === $type ? print 'ER» ' . $buffer : (print '» ' . $buffer);
         });
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput());
     }
     try {
         $this->process->start();
     } catch (\Exception $e) {
         return Result::error($this, $e->getMessage());
     }
     return Result::success($this);
 }
示例#19
0
 /**
  * @param string $serialized
  *
  * @return Process
  */
 public function deserialize($serialized)
 {
     $data = json_decode($serialized, true);
     $process = new Process($data['command']);
     $process->setTimeout($data['timeout']);
     return $process;
 }
 private function install(OutputInterface $output, $targetFolder, $symlinkName, $forceDownload, HttpSource $source)
 {
     $version = $source->getVersion();
     $extractedFolder = 'PhpStorm-' . $version;
     if (is_dir($targetFolder . '/' . $extractedFolder) && false === $forceDownload) {
         $output->writeln(sprintf('<comment>Phpstorm <info>%s</info> already exists, skipping download..</comment>', $version));
     } else {
         $output->write(sprintf('<comment>Download %s </comment><info>%s</info><comment>...</comment>', $source->getName(), $version));
         $downloadProcess = new Process(sprintf("wget %s -O phpstorm.tar.gz", escapeshellarg($source->getUrl())));
         $downloadProcess->setTimeout(3600);
         $downloadProcess->run();
         $output->writeln(' <info>OK</info>');
         if (!$downloadProcess->isSuccessful()) {
             throw new \RuntimeException($downloadProcess->getErrorOutput());
         }
         $output->write('<comment>Extracting...</comment>');
         $extractProcess = new Process(sprintf('tar xfz phpstorm.tar.gz; rm phpstorm.tar.gz; mv %1$s %2$s', escapeshellarg($extractedFolder), escapeshellarg($targetFolder)));
         $extractProcess->run();
         $output->writeln(' <info>OK</info>');
         if (!$extractProcess->isSuccessful()) {
             throw new \RuntimeException($extractProcess->getErrorOutput());
         }
     }
     $output->write('<comment>Linking...</comment>');
     $command = sprintf('cd %2$s && ln -s -f -T %1$s %3$s', escapeshellarg($extractedFolder), escapeshellarg($targetFolder), escapeshellarg($symlinkName));
     $linkProcess = new Process($command);
     $linkProcess->run();
     $output->writeln(' <info>OK</info>');
     if (!$linkProcess->isSuccessful()) {
         throw new \RuntimeException($linkProcess->getErrorOutput());
     }
 }
示例#21
0
 /**
  * @inheritDoc
  */
 protected function execute(InputInterface $input, OutputInterface $output, $retried = false)
 {
     if ($this->getContainer()->get('foreman.accessor')->ping()) {
         $output->writeln('<error>The Foreman Processor server is already running.');
         return;
     }
     if ($input->getOption('daemon')) {
         $phpPath = (new PhpExecutableFinder())->find();
         $process = new Process($phpPath . ' app/console foreman:processor:start' . ($input->getOption('verbose') ? ' -v' : ''));
         $process->setTimeout(0);
         $output->writeln('<info>Starting daemon server...');
         $process->start();
         $accessor = $this->getContainer()->get('foreman.accessor');
         $start = time();
         $interval = $this->getContainer()->getParameter('foreman.processor')['interval'];
         //When we try to ping the server the first time, it almost always fails.
         //The server isn't started yet by the time we get here, so we wait.
         //Timeout = 3 seconds. Should be enough for all servers.
         while (!$accessor->ping() && time() - $start < 3) {
             sleep($interval);
         }
         if ($accessor->ping()) {
             $status = $accessor->status();
             $output->writeln('<info>The server was started successfully with PID ' . $status['pid'] . '</info>');
         } else {
             $output->writeln('<error>The server could not be started at this moment.</error>');
             $output->writeln('Please check if the server port (' . $this->getContainer()->getParameter('foreman.processor.port') . ') is available.');
             $output->writeln('If you have closed the server recently, the connection may not have released. Try again ' . 'in a few seconds.');
         }
     } else {
         $output->writeln('<info>Starting the Foreman Processor...</info>');
         $this->getContainer()->get('foreman.processor')->start($output, $input->getOption('verbose'));
     }
 }
示例#22
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $container = $this->getApplication()->getContainer();
     $commandFile = realpath($_SERVER['SCRIPT_FILENAME']);
     $currentVersion = "v" . $container->getVersion();
     $updateVersion = trim(@file_get_contents('https://raw.githubusercontent.com/kohkimakimoto/altax/master/version'));
     if (!$container->isPhar()) {
         $output->writeln('<error>You can not update altax. Because altax only supports self-update command on PHAR file version.</error>');
         return 1;
     }
     if (!preg_match('/^v[0-9].[0-9]+.[0-9]+$/', $updateVersion)) {
         $output->writeln('<error>You can not update altax. Because the latest version of altax are not available for download.</error>');
         return 1;
     }
     if ($currentVersion === $updateVersion) {
         $output->writeln('<info>You are already using altax version <comment>' . $updateVersion . '</comment>.</info>');
         return 0;
     }
     $output->writeln(sprintf("Updating to version <info>%s</info>.", $updateVersion));
     $tmpDir = "/tmp/" . uniqid("altax.update.");
     $process = new Process("mkdir {$tmpDir} && cd {$tmpDir} && curl -L https://raw.githubusercontent.com/kohkimakimoto/altax/master/installer.sh | bash -s local {$updateVersion}");
     $process->setTimeout(null);
     if ($process->run() !== 0) {
         $output->writeln('<error>You can not update altax.');
         return 1;
     }
     $fs = new Filesystem();
     $fs->copy($tmpDir . "/altax.phar", $commandFile, true);
     $fs->remove($tmpDir);
     $output->writeln("Done.");
 }
示例#23
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Defining crontab task...</info>');
     $output->writeln('<info>Please enter the frequency of data aggregating</info> <comment>(frequency must be equal "pinba_stats_history" of the pinba engine config)</comment>.');
     $dialog = $this->getHelperSet()->get('dialog');
     $frequency = $dialog->askAndValidate($output, 'Frequency (in minutes, default "15"): ', function ($answer) {
         if (intval($answer) <= 0) {
             throw new \RunTimeException('You must enter positive integer value');
         }
         return $answer;
     }, false, '15');
     $process = new Process('crontab -l');
     $process->setTimeout(20);
     $process->run();
     $crontabString = $process->isSuccessful() ? $process->getOutput() : '';
     $path = realpath(__DIR__ . '/../../../console');
     $command = '*/' . $frequency . ' * * * * ' . $path . ' aggregate';
     if (strpos($crontabString, $command) === false) {
         $crontabString .= "\n" . $command . "\n";
     }
     $file = tempnam(sys_get_temp_dir(), 'ipm');
     file_put_contents($file, $crontabString);
     $process = new Process('crontab ' . $file);
     $process->setTimeout(20);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     $output->writeln('<info>Crontab task are defined successfully</info>');
     $output->writeln('<info>Please set parameter "aggregation_period" to value "PT' . $frequency . 'M" in config/parameters.yml</info>');
 }
示例#24
0
 /**
  * @param $path
  * @return Process
  */
 protected function lintFile($path)
 {
     $lintProcess = new Process('php -l ' . ProcessUtils::escapeArgument($path));
     $lintProcess->setTimeout(null);
     $lintProcess->run();
     return strpos($lintProcess->getOutput(), 'No syntax errors detected in') === 0;
 }
 /**
  * Run a terminal command
  * @param  [array]         $command  [description]
  * @param  [path]          $directory [description]
  * @param  OutputInterface $output    [description]
  * @return [void]                     [description]
  */
 private function runProcess($command, $directory, $output, $alias)
 {
     $output->writeln('');
     if (is_array($command['line'])) {
         $commandLine = implode(' && ', $command['line']);
     } else {
         $commandLine = $command['line'];
     }
     $process = new Process($commandLine, $directory);
     $process->setTimeout(7600);
     $process->start();
     if ($output->isVerbose()) {
         $process->wait(function ($type, $buffer) {
             echo $buffer;
         });
     } else {
         $progress = new ProgressBar($output);
         $progress->setFormat("<comment>%message%</comment> [%bar%]");
         $progress->setMessage($command['title']);
         $progress->start();
         $progress->setRedrawFrequency(10000);
         while ($process->isRunning()) {
             $progress->advance();
         }
         $progress->finish();
         $progress->clear();
     }
     $output->writeln('');
     $output->write('<comment>' . $command['title'] . ' </comment><info>√ done</info>');
 }
 public function dump()
 {
     if ($this->pass != "") {
         $exportPasswordCommand = 'PGPASSWORD="******"';
         $exportPasswordProcess = new Process($exportPasswordCommand);
         $exportPasswordProcess->run();
     }
     $this->auth = sprintf("-U '%s' -h '%s' -p '%s'", $this->user, $this->host, $this->port);
     if ($this->database == "") {
         $command = sprintf('pg_dumpall %s > %s', $this->auth, $this->backupPath . $this->backupFilename);
     } else {
         $command = sprintf('pg_dump %s %s > %s', $this->auth, $this->database, $this->backupPath . $this->backupFilename);
     }
     $process = new Process($command);
     $process->setTimeout(null);
     $process->run();
     if (!$process->isSuccessful()) {
         $this->result['status'] = 0;
         $this->result['message'] = $process->getErrorOutput();
     } else {
         echo $process->getOutput();
         $this->result['status'] = 1;
         $this->result['message'] = "Successful backup of PostgreSQL in local file: " . $this->backupPath . $this->backupFilename;
         $this->result['backup_path'] = $this->backupPath;
         $this->result['backup_filename'] = $this->backupFilename;
         $this->result['backup_name'] = $this->backupName;
         $this->result['full_path'] = $this->backupPath . $this->backupFilename;
         $this->result['host'] = $this->host;
     }
     return $this->result;
 }
 /**
  * Create process that lint PHP file.
  *
  * @param string $path path to file
  *
  * @return Process
  */
 public function createProcessForFile($path)
 {
     $process = new Process('php -l ' . ProcessUtils::escapeArgument($path));
     $process->setTimeout(null);
     $process->run();
     return $process;
 }
示例#28
0
文件: Exec.php 项目: stefanhuber/Robo
 public function run()
 {
     $command = $this->getCommand();
     $dir = $this->workingDirectory ? " in " . $this->workingDirectory : "";
     $this->printTaskInfo("Running <info>{$command}</info>{$dir}");
     $this->process = new Process($command);
     $this->process->setTimeout($this->timeout);
     $this->process->setIdleTimeout($this->idleTimeout);
     $this->process->setWorkingDirectory($this->workingDirectory);
     if (isset($this->env)) {
         $this->process->setEnv($this->env);
     }
     if (!$this->background and !$this->isPrinted) {
         $this->startTimer();
         $this->process->run();
         $this->stopTimer();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
     }
     if (!$this->background and $this->isPrinted) {
         $this->startTimer();
         $this->process->run(function ($type, $buffer) {
             print $buffer;
         });
         $this->stopTimer();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
     }
     try {
         $this->process->start();
     } catch (\Exception $e) {
         return Result::error($this, $e->getMessage());
     }
     return Result::success($this);
 }
示例#29
0
 protected function dump_base(base $base, InputInterface $input, OutputInterface $output)
 {
     $date_obj = new DateTime();
     $filename = sprintf('%s%s_%s.sql', p4string::addEndSlash($input->getArgument('directory')), $base->get_dbname(), $date_obj->format('Y_m_d_H_i_s'));
     $command = sprintf('mysqldump %s %s %s %s %s %s --default-character-set=utf8', '--host=' . escapeshellarg($base->get_host()), '--port=' . escapeshellarg($base->get_port()), '--user='******'--password='******'--databases', escapeshellarg($base->get_dbname()));
     if ($input->getOption('gzip')) {
         $filename .= '.gz';
         $command .= ' | gzip -9';
     } elseif ($input->getOption('bzip')) {
         $filename .= '.bz2';
         $command .= ' | bzip2 -9';
     }
     $output->write(sprintf('Generating <info>%s</info> ... ', $filename));
     $command .= ' > ' . escapeshellarg($filename);
     $process = new Process($command);
     $process->setTimeout((int) $input->getOption('timeout'));
     $process->run();
     if (!$process->isSuccessful()) {
         $output->writeln('<error>Failed</error>');
         return 1;
     }
     if (file_exists($filename) && filesize($filename) > 0) {
         $output->writeln('OK');
         return 0;
     } else {
         $output->writeln('<error>Failed</error>');
         return 1;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('site')) {
         $output->writeln('Please provide an <info>--site=SITE_ID</info> option or the <info>--site=all</info> directive');
         $output->writeln('');
         $output->writeln(sprintf(' % 5s - % -30s - %s', 'ID', 'Name', 'Url'));
         foreach ($this->getSiteManager()->findBy(array()) as $site) {
             $output->writeln(sprintf(' % 5s - % -30s - %s', $site->getId(), $site->getName(), $site->getUrl()));
         }
         return;
     }
     foreach ($this->getSites($input) as $site) {
         if ($input->getOption('site') != 'all') {
             if ($input->getOption('mode') == 'async') {
                 $output->write(sprintf('<info>%s</info> - Publish a notification command ...', $site->getName()));
             } else {
                 $output->write(sprintf('<info>%s</info> - Generating snapshots ...', $site->getName()));
             }
             $this->getNotificationBackend($input->getOption('mode'))->createAndPublish('sonata.page.create_snapshots', array('siteId' => $site->getId(), 'mode' => $input->getOption('mode')));
             $output->writeln(' done!');
         } else {
             $p = new Process(sprintf('%s sonata:page:create-snapshots --env=%s --site=%s --mode=%s %s ', $input->getOption('base-console'), $input->getOption('env'), $site->getId(), $input->getOption('mode'), $input->getOption('no-debug') ? '--no-debug' : ''));
             $p->setTimeout(0);
             $p->run(function ($type, $data) use($output) {
                 $output->write($data, OutputInterface::OUTPUT_RAW);
             });
         }
     }
     $output->writeln('<info>done!</info>');
 }