本文整理汇总了PHP中Symfony\Component\Process\Process::isRunning方法的典型用法代码示例。如果您正苦于以下问题:PHP Process::isRunning方法的具体用法?PHP Process::isRunning怎么用?PHP Process::isRunning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Process\Process
的用法示例。
在下文中一共展示了Process::isRunning方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testControlledExit
public function testControlledExit()
{
if (!extension_loaded('pcntl')) {
$this->markTestSkipped('PCNTL extension is not loaded.');
}
$proc = new Process('exec ' . PHP_BINARY . ' ' . escapeshellarg(__DIR__ . '/console') . ' jms-job-queue:run --worker-name=test --verbose --max-runtime=999999');
$proc->start();
usleep(500000.0);
$this->assertTrue($proc->isRunning(), 'Process exited prematurely: ' . $proc->getOutput() . $proc->getErrorOutput());
$this->assertTrueWithin(3, function () use($proc) {
return false !== strpos($proc->getOutput(), 'Signal Handlers have been installed');
}, function () use($proc) {
$this->fail('Signal handlers were not installed: ' . $proc->getOutput() . $proc->getErrorOutput());
});
$proc->signal(SIGTERM);
$this->assertTrueWithin(3, function () use($proc) {
return false !== strpos($proc->getOutput(), 'Received SIGTERM');
}, function () use($proc) {
$this->fail('Signal was not received by process within 3 seconds: ' . $proc->getOutput() . $proc->getErrorOutput());
});
$this->assertTrueWithin(3, function () use($proc) {
return !$proc->isRunning();
}, function () use($proc) {
$this->fail('Process did not terminate within 3 seconds: ' . $proc->getOutput() . $proc->getErrorOutput());
});
$this->assertContains('All jobs finished, exiting.', $proc->getOutput());
}
示例2: testHttpDataDownloadUsingManyWorkers
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');
}
示例3: getStatus
function getStatus()
{
if ($this->process->isRunning()) {
return TestInterface::STATUS_RUNNING;
} elseif ($this->process->getExitCode() > 0) {
return TestInterface::STATUS_FAIL;
} else {
return TestInterface::STATUS_OK;
}
}
示例4: heartbeat
/**
* @inheritdoc
*/
public function heartbeat()
{
if ($this->stopped) {
return false;
}
if ($this->process->isRunning()) {
$this->heartbeatCallback();
return true;
} else {
$this->stopped = true;
return false;
}
}
示例5: testSleeperCommand
/**
* @group console
*/
public function testSleeperCommand()
{
// init
$sleeperCommand = new SleeperCommand();
$sleeperCommandLockFilePath = sprintf('%s/lock_command_%s', $this->getClient()->getKernel()->getCacheDir(), str_replace(':', '_', $sleeperCommand->getName()));
$commandline = sprintf('env bin/console --env=%s %s', $this->getClient()->getKernel()->getEnvironment(), $sleeperCommand->getName());
// the first run of this command with the locking mechanism: the lock is created
$firstProcess = new Process($commandline);
$firstProcess->start();
sleep(SleeperCommand::SLEEPING_TIME / 2);
// the second run of this command is invalid
$secondProcess = new Process($commandline);
$secondProcess->run();
$this->assertSame(2, $secondProcess->getExitCode(), 'Invalid exit code');
$secondProcessOutput = $secondProcess->getOutput();
$this->assertSame(2, substr_count($secondProcessOutput, PHP_EOL), 'There is more than two lines');
$this->assertContains('locking is activated', $secondProcessOutput, 'Incorrect line 1');
$this->assertContains('will not be started', $secondProcessOutput, 'Incorrect line 2');
// check the first process is still running
$this->assertTrue($firstProcess->isRunning(), sprintf('The command %s does not work', $firstProcess->getCommandLine()));
// after the sleeping, the lock is released
sleep(1 + SleeperCommand::SLEEPING_TIME / 2);
$this->assertSame(0, $firstProcess->getExitCode());
$firstProcessOutput = $firstProcess->getOutput();
$this->assertSame(3, substr_count($firstProcessOutput, PHP_EOL), 'There is more than three lines');
$this->assertContains('starting', $firstProcessOutput);
$this->assertContains('processing', $firstProcessOutput);
$this->assertContains('ending', $firstProcessOutput);
// the third run of this command, after the sleeping, is valid
$thirdProcess = new Process($commandline);
$thirdProcess->run();
$this->assertSame(0, $thirdProcess->getExitCode());
}
示例6: runProcess
/**
* 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>');
}
示例7: execute
/**
* @override
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->output = $output;
$this->input = $input;
$tmpRouter = tempnam(sys_get_temp_dir(), 'soup-router') . '.php';
file_put_contents($tmpRouter, '<?php
$possibleFilePath = "' . BOX_PATH . '/Resources/Assets" . $_SERVER["REQUEST_URI"];
if (file_exists($possibleFilePath) & !is_dir($possibleFilePath)) {
$types = array(
"css" => "Content-Type: text/css",
"js" => "Content-Type: text/javascript"
);
$extension = pathinfo($possibleFilePath, PATHINFO_EXTENSION);
if (isset($types[$extension])) {
header($types[$extension]);
}
readfile($possibleFilePath);
} else {
require("' . BOX_PATH . '/src/Bootstrap.php");
}
');
$process = new Process('php -S localhost:1716 ' . $tmpRouter);
$process->start();
$output->writeln('server running on http://localhost:1716 (ctrl+c to quit)');
while ($process->isRunning()) {
// this is just a keep-alive,
// if we don't sleep here the cpu process goes crazy without anything
// to do, since we have to wait, we can wait forever as well
sleep(PHP_INT_MAX);
}
}
示例8: writeAction
/**
* @Route("/", name="write_register", options={"expose"=true})
* @param Request $request
* @return JsonResponse
*/
public function writeAction(Request $request)
{
if ($request->isXmlHttpRequest()) {
$value = $request->get("value");
$register_id = $request->get("register_id");
$registerRepo = $this->getDoctrine()->getRepository('BmsConfigurationBundle:Register');
$register = $registerRepo->find($register_id);
$em = $this->getDoctrine()->getManager();
$write = new RegisterWriteData();
$write->setRegister($register)->setGetToProcess(0)->setValue($value)->setSuccessWrite(0)->setTimeOfUpdate(new \DateTime())->setUsername($this->getUser());
$em->persist($write);
$em->flush();
$vpn = $this->getParameter('vpn');
$exe = "ssh pi@" . $vpn . " ./bin/addToWrite.sh " . $register_id . " " . $value . " " . $this->getUser();
$process = new Process($exe);
$process->start();
while ($process->isRunning()) {
// waiting for process to finish
}
$ret['output'] = $process->getOutput();
return new JsonResponse($ret);
} else {
throw new AccessDeniedHttpException();
}
}
示例9: stop
protected function stop()
{
if ($this->background && $this->process->isRunning()) {
$this->process->stop();
$this->printTaskInfo("Stopped {command}", ['command' => $this->getCommand()]);
}
}
示例10: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->setGithubToken($output);
$packageName = $input->getArgument('package');
$packageNameVersion = PackageNameVersionExtractor::fromString($packageName);
$package = new Package($packageNameVersion->name, $packageNameVersion->version);
$bowerphp = $this->getBowerphp($output);
$url = $bowerphp->getPackageInfo($package);
$default = $this->getDefaultBrowser();
$arg = "{$default} \"{$url}\"";
if (OutputInterface::VERBOSITY_DEBUG <= $output->getVerbosity()) {
$output->writeln($arg);
} else {
$output->writeln('');
}
// @codeCoverageIgnoreStart
if (!defined('PHPUNIT_BOWER_TESTSUITE')) {
$browser = new Process($arg);
$browser->start();
while ($browser->isRunning()) {
// do nothing...
}
}
// @codeCoverageIgnoreEnd
}
示例11: stop
protected function stop()
{
if ($this->background && $this->process->isRunning()) {
$this->process->stop();
$this->printTaskInfo("Stopped <info>" . $this->getCommand() . "</info>");
}
}
示例12: stop
public function stop()
{
if ($this->background && $this->process->isRunning()) {
$this->process->stop();
$this->printTaskInfo("stopped <info>{$this->command}</info>");
}
}
示例13: tick
/**
* {@inheritdoc}
*/
public function tick()
{
if (!$this->process->isRunning() && $this->outputBuffer->isEmpty()) {
usleep(1000);
if ($this->outputBuffer->isEmpty()) {
if ($this->process->isSuccessful()) {
$this->deferred->resolve(new MessageEvent($this, $this->process->getOutput()));
} else {
$this->deferred->reject(new MessageEvent($this, $this->process->getOutput()));
}
return;
}
}
if (!$this->outputBuffer->isEmpty()) {
$this->deferred->notify(new MessageEvent($this, $this->outputBuffer->dequeue()[1]));
}
}
示例14: procesaCola
public function procesaCola()
{
if ((!$this->excelProcess || !$this->excelProcess->isRunning()) && ($siguentePedido = $this->cola->getFirst())) {
try {
$this->crearExcel($siguentePedido);
$this->cola->limpiarUltimoPedido();
} catch (\Exception $e) {
$this->info('|-- Archivo excel bloqueado. Esperando...');
return false;
}
$this->excelProcess = new Process('excel "' . config("roomsApi.macroInicial") . '"');
$this->excelProcess->start();
$this->info('|- abriendo excel');
return true;
}
return false;
}
示例15: beforeTest
public function beforeTest(TestEvent $event)
{
if (!$this->process->isRunning()) {
return;
}
/** @var \RemoteWebDriver $driver */
$driver = $this->getModule('WebDriver')->webDriver;
$this->writeln(["\n", "SauceLabs Connect Info: ", sprintf('SauceOnDemandSessionID=%s job-name=%s', $driver->getSessionID(), $event->getTest()->getName()), ""]);
}