本文整理汇总了PHP中Symfony\Component\Process\Process::getIncrementalOutput方法的典型用法代码示例。如果您正苦于以下问题:PHP Process::getIncrementalOutput方法的具体用法?PHP Process::getIncrementalOutput怎么用?PHP Process::getIncrementalOutput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Process\Process
的用法示例。
在下文中一共展示了Process::getIncrementalOutput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processOutput
/**
* Looks into and processes the child's output
*
* @param string $childName
* @return void
*/
public function processOutput($childName)
{
$output = $this->outputBuffer . $this->process->getIncrementalOutput();
$errorOutput = $this->errorOutputBuffer . $this->process->getIncrementalErrorOutput();
$outputLines = explode("\n", $output);
$errorOutputLines = explode("\n", $errorOutput);
if (count($outputLines) > 0) {
$lastItem = array_pop($outputLines);
$this->outputBuffer = $lastItem;
$this->bufferLength += implode("\n", $outputLines);
foreach ($outputLines as $line) {
if (strstr($line, "[[CHILD::BUSY]]")) {
$this->parent->verboseOutput('<info>' . $childName . ' BUSY</info>');
$this->status = ChildProcessContainer::STATUS_BUSY;
} elseif (strstr($line, "[[CHILD::READY]]")) {
$this->parent->verboseOutput('<info>' . $childName . ' READY</info>');
if ($this->status != ChildProcessContainer::STATUS_BUSY_BUT_SLEEPY) {
$this->status = ChildProcessContainer::STATUS_READY;
} else {
$this->status = ChildProcessContainer::STATUS_SLEEPY;
}
} elseif (strlen($line) > 0) {
$this->parent->verboseOutput('<info>OUTPUT ' . $childName . ':</info>' . $line);
}
}
}
if (count($errorOutputLines) > 0) {
$lastItemError = array_pop($errorOutputLines);
$this->errorOutputBuffer = $lastItemError;
$knownErrorOutput = implode("\n", $errorOutputLines);
$this->bufferLength += strlen($knownErrorOutput);
}
}
示例2: killExistingSocketServer
private function killExistingSocketServer()
{
// If socket already started
$command = 'lsof -n -i4TCP:' . $this->socketPort . ' | grep LISTEN';
$lsOfProcess = new Process($command);
$lsOfProcess->run();
$lsOfProcessOutput = $lsOfProcess->getIncrementalOutput();
if (strlen($lsOfProcessOutput) > 0) {
// Kill process
$lsOfProcessOutput = preg_replace('/\\s+/', ' ', $lsOfProcessOutput);
$lsOfProcessOutput = explode(' ', $lsOfProcessOutput);
$pid = $lsOfProcessOutput[1];
$killProcess = new Process("kill {$pid}");
$killProcess->mustRun();
}
}
示例3: fire
/**
* Fire and forget a command. It will be executed asynchronously, but you can get its output via the $callback.
*
* @param string $cmd Command to be fired.
* @param callable $callback [optional] Callback function that will be called periodically during command's execution
* and will take two arguments: 1st is a string buffer output and 2nd is bool error.
* You can return (bool) false from the callback to stop the running command.
*/
public function fire($cmd, $callback = null)
{
$process = new SymfonyProcess($cmd);
$process->start();
// if callback is defined then call it periodically
if (is_callable($callback)) {
while ($process->isRunning()) {
// call the callback
$continue = call_user_func_array($callback, array($process->getIncrementalOutput()));
// if callback returned false then stop the process
if ($continue === false) {
$process->stop(3, SIGINT);
}
}
}
}
示例4: startProcess
private function startProcess($port, $respond, $callback)
{
$env = array('PORT' => $port, 'RESPOND' => $respond);
$process = new Process('php tests/bin/server.php', null, $env);
$process->start();
// give it time to start
while ($process->getIncrementalOutput() !== 'started') {
usleep(100);
}
try {
$callback();
} catch (Exception $e) {
$process->signal(SIGKILL);
$process->stop();
throw $e;
}
}
示例5: execute
/**
* Executes post install SH script
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param OutputInterface $output
*
* @internal param \Symfony\Component\Console\Input\InputInterface $intput
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$command = $input->getOption("post");
$output->writeln("");
$output->writeln("========================");
$output->writeln('Executing post ' . $command . ' script.');
$output->writeln("========================");
// TODO: openssl req -new -x509 -sha256 -days 365 -nodes -out /tmp/server.crt -keyout /tmp/server.key
$process = new Process("/bin/bash ./src/FIT/NetopeerBundle/bin/netconfwebgui-postinstall.sh");
$process->run();
while ($process->isRunning()) {
$process->getIncrementalOutput();
$process->getIncrementalErrorOutput();
}
if (!$process->isSuccessful()) {
$output->writeln("Error in post " . $command . " script occured.");
$output->writeln($process->getErrorOutput());
} else {
$output->writeln($process->getOutput());
}
$output->writeln("========================");
$output->writeln("End of post " . $command . " script");
$output->writeln("========================");
}
示例6: testGetIncrementalOutput
public function testGetIncrementalOutput()
{
$p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) { echo \' foo \'; usleep(50000); $n++; }')));
$p->start();
while ($p->isRunning()) {
$this->assertLessThanOrEqual(1, preg_match_all('/foo/', $p->getIncrementalOutput(), $matches));
usleep(20000);
}
}
示例7: execute
/**
* Execute
*
* @return Funstaff\Tika\Wrapper
*/
public function execute()
{
$base = $this->generateCommand();
foreach ($this->document as $name => $doc) {
if ($doc->getPassword()) {
$command = sprintf('%s --password=%s', $base, $doc->getPassword());
} else {
$command = $base;
}
$command = sprintf('%s %s', $command, escapeshellarg($doc->getPath()));
if ($this->logger) {
$this->logger->addInfo(sprintf('Tika command: "%s"', $command));
}
$process = new Process($command);
$process->run();
if (!$process->isSuccessful()) {
throw new \InvalidArgumentException($process->getErrorOutput());
}
$content = $process->getIncrementalOutput();
$doc->setRawContent($content);
if ($this->config->getMetadataOnly()) {
$this->loadMetadata($doc, $content);
} else {
if (in_array($this->config->getOutputFormat(), array('xml', 'html'))) {
$this->loadDocument($doc, $content);
} else {
$doc->setContent($content);
}
}
}
return $this;
}
示例8: runProcess
/**
* @param string $command
* @return string
*
* @throws \RuntimeException
*/
protected function runProcess($command)
{
$process = new Process($command);
$process->run();
if (!$process->isSuccessful()) {
throw new \InvalidArgumentException($process->getErrorOutput());
}
return $process->getIncrementalOutput();
}
示例9: startServer
/**
* @param $address
* @param $environment
*/
protected function startServer()
{
$publicDir = $this->getApplication()->getWorkingPath() . DS . 'public';
$shellCommand = $this->getBaseCommand();
$process = new Process($shellCommand, $publicDir);
if ($this->getInput()->getOption('background')) {
$process->disableOutput();
$process->start();
$processId = $this->getProcessId();
$this->getApplication()->getConfig()->setOption('server', ['pid' => $processId, 'address' => $address = 'http://' . $this->getAddress()]);
$this->getOutput()->writeln($this->info('Server has been started at ' . $address));
} else {
while ($process instanceof Process) {
if (!$process->isStarted()) {
$process->start();
continue;
}
echo $process->getIncrementalOutput();
echo $process->getIncrementalErrorOutput();
if (!$process->isRunning() || $process->isTerminated()) {
$process = false;
$this->getOutput()->writeln("");
$this->getOutput()->writeln($this->info('Server has been stopped.'));
}
sleep(1);
}
}
}
示例10: execute_behat_generator
/**
* Execute behat command for featurename and return exit status.
*
* @param string $featurename name of the feature
* @param string $featurepath path of feature file
* @return int status code.
*/
protected function execute_behat_generator($featurename, $featurepath)
{
$cmd = "vendor/bin/behat --config " . util::get_tool_dir() . DIRECTORY_SEPARATOR . 'behat.yml ' . $featurepath;
$process = new symfonyprocess($cmd);
$process->setWorkingDirectory(__DIR__ . "/../../moodle");
$process->setTimeout(null);
$process->start();
if ($process->getStatus() !== 'started') {
echo "Error starting process: {$featurename}";
$process->signal(SIGKILL);
exit(1);
}
while ($process->isRunning()) {
$output = $process->getIncrementalOutput();
// Don't show start data everytime.
$output = preg_replace('/[a-z0-9.\\(\\)].*/im', '', $output);
$op = trim($output);
if (!empty($op)) {
echo $output;
}
}
return $process->getExitCode();
}
示例11: updateRelease
/**
* @param Process $process
* @return callable
*/
public function updateRelease(Process $process)
{
$out = $process->getIncrementalOutput() . $process->getIncrementalErrorOutput();
$this->release->update(['raw_log' => $process->getOutput() . PHP_EOL . $process->getErrorOutput()]);
if (!empty($out)) {
$this->release->logger()->info($out);
}
}
示例12: execute_behat_generator
/**
* Execute behat command for featurename and return exit status.
*
* @return int status code.
*/
protected function execute_behat_generator()
{
$cmd = "vendor/bin/behat --config " . util::get_tool_dir() . DIRECTORY_SEPARATOR . 'behat.yml ';
$process = new Process($cmd);
$process->setWorkingDirectory(__DIR__ . "/../../../../../");
$process->setTimeout(null);
$process->start();
if ($process->getStatus() !== 'started') {
echo "Error starting process";
$process->signal(SIGKILL);
exit(1);
}
while ($process->isRunning()) {
$output = $process->getIncrementalOutput();
$op = trim($output);
if (!empty($op)) {
echo $output;
}
}
if ($process->getExitCode() !== 0) {
echo $process->getErrorOutput();
}
return $process->getExitCode();
}
示例13: processContractDocument
/**
* @param $writeFolderPath
* @param $readFilePath
* @return bool
*/
public function processContractDocument($writeFolderPath, $readFilePath)
{
set_time_limit(0);
$commandPath = config('nrgi.pdf_process_path');
$command = sprintf('python %s/run.py -i %s -o %s', $commandPath, $readFilePath, $writeFolderPath);
$this->logger->info("processing command", ['command' => $command]);
$process = new Process($command);
$process->setTimeout(360 * 10);
$process->start();
while ($process->isRunning()) {
echo $process->getIncrementalOutput();
}
if (!$process->isSuccessful()) {
//todo remove folder
$this->logger->error("error while executing command.{$process->getErrorOutput()}", ['command' => $command]);
throw new \RuntimeException($process->getErrorOutput());
}
return true;
}
示例14: jobExists
/**
* search job in jobs
*
* @param string $job
* @return mixed
*/
public function jobExists($job = '')
{
$process = new Process('crontab -l');
$process->run();
$output = $process->getIncrementalOutput();
$jobs = array_filter(explode(PHP_EOL, $output), function ($line) {
return '' != trim($line);
});
return is_array($jobs) ? array_search($job, $jobs) : false;
}
示例15: getProcessOutput
/**
* Decorate and return Process output
* @param Process $process
* @return string
*/
protected function getProcessOutput(Process $process)
{
$output = '';
// Add standard process output
if ($processOutput = $process->getIncrementalOutput()) {
$processOutputLines = explode("\n", $processOutput);
// color output lines containing "[WARN]"
foreach ($processOutputLines as &$processOutputLine) {
if (strpos($processOutputLine, '[WARN]') !== false) {
$processOutputLine = '<fg=black;bg=yellow>' . $processOutputLine . '</fg=black;bg=yellow>';
} elseif (strpos($processOutputLine, '[DEBUG]') !== false) {
$processOutputLine = '<comment>' . $processOutputLine . '</comment>';
}
}
$output .= implode("\n", $processOutputLines);
}
// Add error output
if ($errorOutput = $process->getIncrementalErrorOutput()) {
$output .= '<error>' . rtrim($errorOutput, PHP_EOL) . '</error>' . "\n";
}
return $output;
}