本文整理汇总了PHP中Symfony\Component\Process\PhpProcess::start方法的典型用法代码示例。如果您正苦于以下问题:PHP PhpProcess::start方法的具体用法?PHP PhpProcess::start怎么用?PHP PhpProcess::start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Process\PhpProcess
的用法示例。
在下文中一共展示了PhpProcess::start方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: start
/**
* Starts background proccess
*
* @param \Closure $callback Function to execute if executed application provides output(either STDERR or STDOUT) ($type, $buffer)
*
* @return int The exit status code
*/
public function start($callback = null)
{
$statusCode = $this->symfonyProcess->start($callback);
// give the new process a bit of breathing room
sleep(2);
return $statusCode;
}
示例2: initServer
function initServer()
{
$process = new PhpProcess(file_get_contents(__DIR__ . '/worker.php'), __DIR__);
$process->start();
sleep(5);
return $process;
}
示例3: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var FormatterHelper $formatter */
$formatter = $this->getHelper('formatter');
// $process = new Process('wkhtmltopdf http://google.com/ test.pdf');
// $process->run();
// $process->stop(3, SIGINT);
// $process->mustRun(function ($type, $message) use ($output, $formatter) {
// if ($type === Process::ERR) {
// $output->writeln($formatter->formatBlock($message, 'error'));
// } else {
// $output->writeln($formatter->formatBlock($message, 'comment'));
// }
// });
$process = new PhpProcess(<<<EOF
<?php
sleep(5);
echo "OK
";
?>
EOF
);
$process->start();
$process->stop(2, SIGINT);
if (!$process->isSuccessful()) {
$output->writeln($formatter->formatBlock($process->getErrorOutput(), 'error', true));
return;
}
$output->writeln($formatter->formatSection('success', $process->getOutput()));
}
示例4: testNonBlockingWorks
public function testNonBlockingWorks()
{
$expected = 'hello world!';
$process = new PhpProcess(<<<PHP
<?php echo '{$expected}';
PHP
);
$process->start();
$process->wait();
$this->assertEquals($expected, $process->getOutput());
}
示例5: run
/**
* {@inheritdoc}
*/
public function run(JobReportInterface $report)
{
try {
$this->process->start();
$this->savePid($this->process->getPid(), $report);
while ($this->process->isRunning()) {
// waiting for process to finish
}
if ($this->process->isSuccessful()) {
$report->setOutput(trim($this->process->getOutput()));
return JobState::STATE_FINISHED;
}
$report->setErrorOutput(trim($this->process->getErrorOutput()));
} catch (LogicException $e) {
$report->setErrorOutput($e->getMessage());
} catch (RuntimeException $e) {
$report->setErrorOutput($e->getMessage());
}
return JobState::STATE_FAILED;
}
示例6: start
/**
* Starts the web server.
*
* @param callable $callback An output function to call whenever there is
* a log entry made to the server.
*/
public function start($callback = null)
{
// Find the PHP executable.
if (false === ($php = $this->executableFinder->find())) {
throw new \RuntimeException('Unable to find the PHP executable.');
}
$options = ' -S ' . $this->addr . ':' . $this->port;
if (isset($this->documentRoot)) {
$options .= ' -t ' . $this->documentRoot;
}
$this->setCommandLine($php . $options);
parent::start($callback);
}
示例7: testCommandLine
public function testCommandLine()
{
$process = new PhpProcess(<<<'PHP'
<?php echo 'foobar';
PHP
);
$commandLine = $process->getCommandLine();
$f = new PhpExecutableFinder();
$this->assertContains($f->find(), $commandLine, '::getCommandLine() returns the command line of PHP before start');
$process->start();
$this->assertContains($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after start');
$process->wait();
$this->assertContains($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after wait');
}
示例8: testCommandLine
public function testCommandLine()
{
if ('phpdbg' === PHP_SAPI) {
$this->markTestSkipped('phpdbg SAPI is not supported by this test.');
}
$process = new PhpProcess(<<<PHP
<?php echo 'foobar';
PHP
);
$f = new PhpExecutableFinder();
$commandLine = $f->find();
$this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP before start');
$process->start();
$this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after start');
$process->wait();
$this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after wait');
}
示例9: createWorker
protected function createWorker($id)
{
$files = get_included_files();
if ($_SERVER['PHP_SELF'] != '-') {
array_shift($files);
}
$boostrap = "<?php \n foreach (" . var_export($files, true) . " as \$file) {\n require_once \$file;\n }\n\n define('__WORKER__', " . var_export($id, true) . ");\n\n \$config = crodas\\Worker\\Config::import(" . $this->config->export() . ");\n \$config['worker_id'] = __WORKER__;\n\n \$server = new crodas\\Worker\\Server(\$config);\n \$server->worker();\n ";
$this->log(null, "Starting process {$id}");
$process = new PhpProcess($boostrap);
$process->start();
$process->id = $id;
$process->time = time();
$process->status = empty($args) ? 'idle' : 'busy';
$process->jobs = 0;
$process->failed = 0;
return $process;
}
示例10: createAndRun
/**
* Initiates new actor in a new PHP process
* @param integer $id An unique id of an actor, should be free tcp-port in current implementation
* @param callable $handler
* @return PhpProcess
*/
public static function createAndRun($id, callable $handler)
{
$serializedHandler = base64_encode((new Serializer())->serialize($handler));
$autoloadPath = Utils::getAutoloadPath();
$process = new PhpProcess(<<<EOF
<?php
require '{$autoloadPath}';
\\Phactor\\Phactor\\Actor::initializeChild({$id}, '{$serializedHandler}');
?>
EOF
);
if (null === $process->getCommandLine()) {
$process->setPhpBinary(PHP_BINARY);
}
// workaround for portable windows php
$process->start();
return $process;
}
示例11: testCompressEventsKate
/**
* @medium
* @dataProvider backends
*/
public function testCompressEventsKate($backend)
{
// CREATE web.scssdx1493.new
// MODIFY web.scssdx1493.new
// MOVED_FROM web.scssdx1493.new
// MOVED_TO web.scss
if (!$backend->isAvailable()) {
$this->markTestSkipped();
}
$f = __DIR__ . '/test/';
sleep(1);
$php = "<?php sleep(2);\n file_put_contents('{$f}foo.txtdx1493.new', 'x');\n rename('{$f}foo.txtdx1493.new', '{$f}foo.txt');\n\n file_put_contents('{$f}stop.txt', 'x');\n ";
$process = new PhpProcess($php);
$process->start();
$gotEvents = array();
$backend->setPath(__DIR__ . '/test');
$backend->addListener(ModifyEvent::NAME, function ($e) use(&$gotEvents, $backend) {
$gotEvents[] = 'modify';
});
$backend->addListener(CreateEvent::NAME, function ($e) use(&$gotEvents, $backend) {
if ($e->filename == __DIR__ . '/test/stop.txt') {
$backend->stop();
} else {
$gotEvents[] = 'create';
}
});
$backend->addListener(DeleteEvent::NAME, function ($e) use(&$gotEvents, $backend) {
$gotEvents[] = 'delete';
});
$backend->addListener(MoveEvent::NAME, function ($e) use(&$gotEvents, $backend) {
$gotEvents[] = 'move';
});
$backend->start();
$process->wait();
$this->assertTrue($process->isSuccessful());
$this->assertEquals($gotEvents, array('modify'));
}