当前位置: 首页>>代码示例>>PHP>>正文


PHP Process::signal方法代码示例

本文整理汇总了PHP中Symfony\Component\Process\Process::signal方法的典型用法代码示例。如果您正苦于以下问题:PHP Process::signal方法的具体用法?PHP Process::signal怎么用?PHP Process::signal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Process\Process的用法示例。


在下文中一共展示了Process::signal方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
 }
开发者ID:ezprit,项目名称:JMSJobQueueBundle,代码行数:27,代码来源:SignalTest.php

示例2: iShouldBeAbleToCancelTheCommand

 /**
  * @Then I should be able to cancel the command
  */
 public function iShouldBeAbleToCancelTheCommand()
 {
     // How many seconds to allow it to stop
     $tolerance = 2;
     $this->process->run(function ($type, $buffer) use($tolerance) {
         static $cancelled = false;
         if (!$cancelled) {
             $this->process->signal(15);
             $cancelled = time();
         } else {
             if (time() - $cancelled > $tolerance) {
                 throw new \Exception('Process did not cancel in time, still sending output: ' . $buffer);
             }
         }
     });
     if (!$this->process) {
         throw new LogicException('No process started');
     }
 }
开发者ID:kieljohn,项目名称:TenantBundle,代码行数:22,代码来源:CommandContext.php

示例3: sendTERMSignal

 /**
  * Sends a signal to the process, this method prevents the signal from being sent twice
  *
  * @return void
  */
 private function sendTERMSignal()
 {
     if (!$this->hasReceivedHUP) {
         $this->hasReceivedHUP = true;
         try {
             $this->process->signal(SIGTERM);
         } catch (\Symfony\Component\Process\Exception\LogicException $e) {
             //In case the process ends between checking and actually sending the signal
         }
     }
 }
开发者ID:webdevvie,项目名称:pheanstalk-task-queue-bundle,代码行数:16,代码来源:ChildProcessContainer.php

示例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;
     }
 }
开发者ID:kohabi,项目名称:quake-query,代码行数:17,代码来源:ServerTest.php

示例5: stop

 /**
  * Stops the process.
  */
 public function stop()
 {
     $this->process->signal(SIGTERM);
     $this->process->stop(3, SIGKILL);
 }
开发者ID:mcustiel,项目名称:phiremock-codeception-extension,代码行数:8,代码来源:PhiremockProcess.php

示例6: 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();
 }
开发者ID:rajeshtaneja,项目名称:moodle-performance-tool,代码行数:30,代码来源:generator.php

示例7: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     set_time_limit(0);
     $container = $this->getContainer();
     $env = array('APP_INCLUDE' => $this->getContainer()->getParameter('zym_resque.resque.vendor_dir') . '/autoload.php', 'VVERBOSE' => $input->getOption('verbose'), 'QUEUE' => $input->getArgument('queues'), 'INTERVAL' => (int) $input->getOption('interval'), 'REDIS_BACKEND' => sprintf('%s:%s', $container->getParameter('zym_resque.resque.redis.host'), $container->getParameter('zym_resque.resque.redis.port')));
     $vendorDir = $container->getParameter('zym_resque.resque.vendor_dir');
     // Handle breaking changes in new version of php-resque
     if (file_exists($vendorDir . '/chrisboulton/php-resque/resque.php')) {
         $workerCommand = 'php ' . $vendorDir . '/chrisboulton/php-resque/resque.php';
     } else {
         $workerCommand = $vendorDir . '/chrisboulton/php-resque/bin/resque';
     }
     $process = new Process($workerCommand, $container->getParameter('kernel.root_dir'), $env, null, null);
     $process->start();
     if (function_exists('pcntl_signal')) {
         $worker = $this;
         $signalHandler = function ($signal) use($process, $output, $worker) {
             switch ($signal) {
                 case \SIGTERM:
                     $signalName = 'SIGTERM';
                     break;
                 case \SIGINT:
                     $signalName = 'SIGINT';
                     break;
                 case \SIGQUIT:
                     $signalName = 'SIGQUIT';
                     break;
                 case \SIGUSR1:
                     $signalName = 'SIGUSR1';
                     break;
                 case \SIGUSR2:
                     $signalName = 'SIGUSR2';
                     break;
                 case \SIGCONT:
                     $signalName = 'SIGCONT';
                     break;
                 case \SIGPIPE:
                     $signalName = 'SIGPIPE';
                     break;
                 default:
                     $signalName = $signal;
             }
             $output->writeln(sprintf('<error>%s signal caught</error>', $signalName));
             $worker->signaled = true;
             $process->signal($signal);
         };
         pcntl_signal(\SIGTERM, $signalHandler);
         pcntl_signal(\SIGINT, $signalHandler);
         pcntl_signal(\SIGQUIT, $signalHandler);
         pcntl_signal(\SIGUSR1, $signalHandler);
         pcntl_signal(\SIGUSR2, $signalHandler);
         pcntl_signal(\SIGCONT, $signalHandler);
         pcntl_signal(\SIGPIPE, $signalHandler);
     }
     $output->writeln(\sprintf('Starting worker <info>%s</info>', $process->getCommandLine()));
     $output->writeln('');
     try {
         $process->wait(function ($type, $buffer) use($output) {
             // Color level
             $buffer = preg_replace('/^(\\[info\\])/', '<info>$1</info>', $buffer);
             $buffer = preg_replace('/^(\\[debug\\])/', '<fg=white>$1</fg=white>', $buffer);
             $buffer = preg_replace('/^(\\[notice\\])/', '<comment>$1</comment>', $buffer);
             $buffer = preg_replace('/^(\\[warning\\])/', '<error>$1</error>', $buffer);
             $buffer = preg_replace('/^(\\[critical\\])/', '<error>$1</error>', $buffer);
             // Color timestamp
             $buffer = preg_replace('/(\\*\\* \\[\\d{2}:\\d{2}:\\d{2} \\d{4}-\\d{2}-\\d{2}\\])/', '<comment>$1</comment>', $buffer);
             $buffer = preg_replace('/(\\[\\d{2}:\\d{2}:\\d{2} \\d{4}-\\d{2}-\\d{2}\\])/', '<comment>$1</comment>', $buffer);
             // Color
             $buffer = preg_replace('/\\(Job(.*?)\\|(.*?)\\|(.*?)\\|/', '(Job$1|$2|<info>$3</info>|', $buffer);
             $buffer = preg_replace('/Job{(.*?)}/', '<info>Job{</info><comment>$1</comment><info>}</info>', $buffer);
             $buffer = preg_replace('/(ID:)/', '<info>$1</info>', $buffer);
             // Color failed
             $buffer = preg_replace('/failed/', '<error>$1</error>', $buffer);
             $output->write($buffer);
         });
     } catch (\Symfony\Component\Process\Exception\RuntimeException $e) {
         if (!$this->signaled && !$process->getStopSignal() && !$process->getTermSignal()) {
             throw $e;
         }
     }
     $process->stop();
     $output->writeln('');
     $output->writeln('<info>Worker stopped...</info>');
 }
开发者ID:geoffreytran,项目名称:zym,代码行数:84,代码来源:WorkerCommand.php

示例8: 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();
 }
开发者ID:rajeshtaneja,项目名称:moodle-performance-toolkit,代码行数:29,代码来源:generator.php


注:本文中的Symfony\Component\Process\Process::signal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。