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


PHP Process::getStopSignal方法代码示例

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


在下文中一共展示了Process::getStopSignal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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


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