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


PHP pcntl_signal函数代码示例

本文整理汇总了PHP中pcntl_signal函数的典型用法代码示例。如果您正苦于以下问题:PHP pcntl_signal函数的具体用法?PHP pcntl_signal怎么用?PHP pcntl_signal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: __construct

 /**
  * Constructor
  *
  * @param AMQPQueue[] $queues
  * @param float $idleTimeout in seconds
  * @param int $waitTimeout in microseconds
  * @param callable $deliveryCallback,
  * @param callable|null $flushCallback,
  * @param callable|null $errorCallback
  * @throws Exception\InvalidArgumentException
  */
 public function __construct(array $queues, $idleTimeout, $waitTimeout, callable $deliveryCallback, callable $flushCallback = null, callable $errorCallback = null)
 {
     Assertion::float($idleTimeout);
     Assertion::integer($waitTimeout);
     if (function_exists('pcntl_signal_dispatch')) {
         $this->usePcntlSignalDispatch = true;
     }
     if (function_exists('pcntl_signal')) {
         pcntl_signal(SIGTERM, [$this, 'shutdown']);
         pcntl_signal(SIGINT, [$this, 'shutdown']);
         pcntl_signal(SIGHUP, [$this, 'shutdown']);
     }
     if (empty($queues)) {
         throw new Exception\InvalidArgumentException('No queues given');
     }
     $q = [];
     foreach ($queues as $queue) {
         if (!$queue instanceof AMQPQueue) {
             throw new Exception\InvalidArgumentException('Queue must be an instance of AMQPQueue, ' . is_object($queue) ? get_class($queue) : gettype($queue) . ' given');
         }
         if (null === $this->blockSize) {
             $this->blockSize = $queue->getChannel()->getPrefetchCount();
         }
         $q[] = $queue;
     }
     $this->idleTimeout = (double) $idleTimeout;
     $this->waitTimeout = (int) $waitTimeout;
     $this->queues = new InfiniteIterator(new ArrayIterator($q));
 }
开发者ID:bweston92,项目名称:HumusAmqp,代码行数:40,代码来源:MultiQueueConsumer.php

示例2: __construct

 function __construct()
 {
     pcntl_signal(SIGINT, array($this, 'cleanShutdown'));
     pcntl_signal(SIGTERM, array($this, 'cleanShutdown'));
     $this->initBot();
     while (true) {
         if (empty($this->servers)) {
             echo 'No servers to read from - Qutting' . "\n";
             break;
         }
         $this->time = time();
         $this->triggerTimers();
         $this->triggerJobs();
         $check = false;
         foreach ($this->servers as $Server) {
             if (false !== ($data = $Server->tick())) {
                 $check = true;
                 if (is_array($data)) {
                     unset($data['raw']);
                     // TODO: Logging & stuff
                     $this->triggerPlugins($data, $Server);
                     $Server->doSendQueue();
                 }
             }
         }
         if (!$check) {
             usleep(20000);
         }
     }
 }
开发者ID:Laxa,项目名称:Nimda3,代码行数:30,代码来源:Nimda.php

示例3: run

 /**
  * Executes the callback in a different thread. All arguments to this method will be passed on to the callback.
  *
  * The callback will be invoked but the script will not wait for it to finish.
  * @return null
  */
 public function run()
 {
     $pid = @pcntl_fork();
     if ($pid == -1) {
         throw new ZiboException('Could not run the thread: unable to fork the callback');
     }
     if ($pid) {
         // parent process code
         $this->pid = $pid;
     } else {
         // child process code
         pcntl_signal(SIGTERM, array($this, 'signalHandler'));
         try {
             $this->callback->invokeWithArrayArguments(func_get_args());
         } catch (Exception $exception) {
             $message = $exception->getMessage();
             if (!$message) {
                 $message = get_class($exception);
             }
             Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $message, $exception->getTraceAsString(), 1);
             echo $message . "\n";
             echo $exception->getTraceAsString();
         }
         exit;
     }
 }
开发者ID:BGCX261,项目名称:zibo-svn-to-git,代码行数:32,代码来源:Thread.php

示例4: sleepUntilThereIsSomethingInteresting

 private function sleepUntilThereIsSomethingInteresting($timeLimit, $child)
 {
     pcntl_signal(SIGALRM, [$this, "alarm"], true);
     pcntl_alarm($timeLimit);
     pcntl_waitpid($child, $status);
     //pcntl_signal_dispatch();
 }
开发者ID:onebip,项目名称:onebip-concurrency,代码行数:7,代码来源:Poison.php

示例5: start

 public function start()
 {
     if ($this->workingPid()) {
         return;
     }
     if ($this->pidfile) {
         if (is_file($this->pidfile)) {
             unlink($this->pidfile);
         }
         file_put_contents($this->pidfile, $this->pid() . PHP_EOL);
     }
     try {
         foreach (get_class_methods($this) as $method) {
             if (0 === strpos($method, '__signal_')) {
                 pcntl_signal(constant('SIG' . strtoupper(substr($method, strlen('__signal_')))), [$this, $method]);
             }
         }
         $this->log('start');
         $this->main();
         $this->log('done');
     } catch (Stop $stop) {
         if ($message = $stop->getMessage()) {
             $this->log($message);
         }
     } catch (\Exception $e) {
         $this->error_log($e);
     } finally {
         if ($this->workingPid() === $this->pid()) {
             unlink($this->pidfile);
         }
     }
 }
开发者ID:noframework,项目名称:noframework,代码行数:32,代码来源:Application.php

示例6: __construct

 function __construct($config)
 {
     if (extension_loaded("pcntl")) {
         //Add signal handlers to shut down the bot correctly if its getting killed
         pcntl_signal(SIGTERM, array($this, "signalHandler"));
         pcntl_signal(SIGINT, array($this, "signalHandler"));
     } else {
         //die("Please make sure the pcntl PHP extension is enabled.\n");
     }
     $this->config = $config;
     $this->startTime = time();
     $this->lastServerMessage = $this->startTime;
     ini_set("memory_limit", $this->config['memoryLimit'] . "M");
     if ($config['verifySSL']) {
         $this->socket = stream_socket_client("" . $config['server'] . ":" . $config['port']) or die("Connection error!");
     } else {
         $socketContext = stream_context_create(array("ssl" => array("verify_peer" => false, "verify_peer_name" => false)));
         $this->socket = stream_socket_client("" . $config['server'] . ":" . $config['port'], $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $socketContext) or die("Connection error!");
     }
     stream_set_blocking($this->socket, 0);
     stream_set_timeout($this->socket, 600);
     $this->login();
     $this->loadPlugins();
     $this->main($config);
 }
开发者ID:sergejey,项目名称:majordomo-app_ircbot,代码行数:25,代码来源:VikingBot.php

示例7: execute

 /**
  * Start the thread
  *
  * @throws RuntimeException
  */
 public function execute()
 {
     $this->threadKey = 'thread_' . rand(1000, 9999) . rand(1000, 9999) . rand(1000, 9999) . rand(1000, 9999);
     if (($this->pid = pcntl_fork()) == -1) {
         throw new RuntimeException('Couldn\'t fork the process');
     }
     if ($this->pid) {
         // Parent
         //pcntl_wait($status); //Protect against Zombie children
     } else {
         // Child.
         pcntl_signal(SIGTERM, array($this, 'signalHandler'));
         $args = func_get_args();
         $callable = $this->callable;
         if (!is_string($callable)) {
             $callable = (array) $this->callable;
         }
         try {
             $return = call_user_func_array($callable, (array) $args);
             if (!is_null($return)) {
                 $this->saveResult($return);
             }
             // Executed only in PHP 7, will not match in PHP 5.x
         } catch (\Throwable $t) {
             $this->saveResult($t);
             // Executed only in PHP 5. Remove when PHP 5.x is no longer necessary.
         } catch (\Exception $ex) {
             $this->saveResult($ex);
         }
         exit(0);
     }
 }
开发者ID:byjg,项目名称:phpthread,代码行数:37,代码来源:ForkHandler.php

示例8: __construct

 /**
  * Setting up and installing the data handler.
  * @param array $entries
  */
 public function __construct($entries)
 {
     $this->entries = $entries;
     pcntl_signal_dispatch();
     pcntl_signal(SIGTERM, array($this, 'signalHandler'));
     pcntl_signal(SIGCHLD, array($this, 'signalHandler'));
 }
开发者ID:dmamontov,项目名称:symfony-phpcron,代码行数:11,代码来源:PHPCron.php

示例9: start

 /**
  * Start
  *
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function start(OutputInterface $output)
 {
     $output->writeln('Starting daemon...');
     if (file_exists($this->pidfile)) {
         $output->writeln('<error>Daemon process is already running</error>');
         return null;
     }
     $pid = pcntl_fork();
     if ($pid == -1) {
         $output->writeln('<error>Could not fork</error>');
         return null;
     } elseif ($pid) {
         file_put_contents($this->pidfile, $pid);
         $output->writeln('Daemon started with PID ' . $pid);
     } else {
         $terminated = false;
         pcntl_signal(SIGTERM, function ($signo) use(&$terminated) {
             if ($signo == SIGTERM) {
                 $terminated = true;
             }
         });
         while (!$terminated) {
             $this->executeOperation();
             pcntl_signal_dispatch();
             sleep(1);
         }
         $output->writeln('Daemon stopped');
     }
 }
开发者ID:neatphp,项目名称:neat,代码行数:36,代码来源:AbstractDaemonCommand.php

示例10: __construct

 /**
  * constructor just initiates the default logger
  * which simply skips every log-message
  *
  **/
 public function __construct()
 {
     $this->cloLogger = function ($strLogLine) {
         return;
     };
     pcntl_signal(SIGCHLD, array($this, 'handleSIGCHLD'));
 }
开发者ID:t-zuehlsdorff,项目名称:asap,代码行数:12,代码来源:Fork.class.php

示例11: configure

 function configure()
 {
     $this->pid = getmypid();
     $this->mode = isset($_REQUEST['jaxl']) ? "cgi" : "cli";
     if (!JAXLUtil::isWin() && JAXLUtil::pcntlEnabled() && $config['sigh'] != FALSE) {
         pcntl_signal(SIGTERM, array($this, "shutdown"));
         pcntl_signal(SIGINT, array($this, "shutdown"));
         JAXLog::log("Registering shutdown for SIGH Terms ...", 0, $this);
     }
     if (JAXLUtil::sslEnabled()) {
         JAXLog::log("Openssl enabled ...", 0, $this);
     }
     if ($this->mode == "cli") {
         if (!function_exists('fsockopen')) {
             die("Jaxl requires fsockopen method ...");
         }
         file_put_contents(JAXL_PID_PATH, $this->pid);
     }
     if ($this->mode == "cgi") {
         if (!function_exists('curl_init')) {
             die("Jaxl requires curl_init method ...");
         }
     }
     // include service discovery XEP, recommended for every IM client
     jaxl_require('JAXL0030', $this, array('category' => 'client', 'type' => 'bot', 'name' => JAXL_NAME, 'lang' => 'en'));
 }
开发者ID:rahijain,项目名称:JAXL,代码行数:26,代码来源:jaxl.class.php

示例12: registerSignalHandlers

 public function registerSignalHandlers()
 {
     if (PHP_OS === 'Linux') {
         pcntl_signal(SIGTERM, array($this, 'signalHandler'));
         pcntl_signal(SIGINT, array($this, 'signalHandler'));
     }
 }
开发者ID:netucz,项目名称:slovicka,代码行数:7,代码来源:Daemon.php

示例13: __construct

 protected function __construct()
 {
     set_error_handler('\\ManiaLive\\Application\\ErrorHandling::createExceptionFromError');
     if (extension_loaded('pcntl')) {
         pcntl_signal(SIGTERM, array($this, 'kill'));
         pcntl_signal(SIGINT, array($this, 'kill'));
         declare (ticks=1);
     }
     try {
         $configFile = CommandLineInterpreter::preConfigLoad();
         // load configuration file
         $loader = Loader::getInstance();
         $loader->setConfigFilename(APP_ROOT . 'config' . DIRECTORY_SEPARATOR . $configFile);
         $loader->run();
         // load configureation from the command line ...
         CommandLineInterpreter::postConfigLoad();
         // add logfile prefix ...
         $manialiveConfig = \ManiaLive\Config\Config::getInstance();
         $serverConfig = \ManiaLive\DedicatedApi\Config::getInstance();
         if ($manialiveConfig->logsPrefix != null) {
             $manialiveConfig->logsPrefix = str_replace('%ip%', str_replace('.', '-', $serverConfig->host), $manialiveConfig->logsPrefix);
             $manialiveConfig->logsPrefix = str_replace('%port%', $serverConfig->port, $manialiveConfig->logsPrefix);
         }
         // disable logging?
         /*if(!$manialiveConfig->runtimeLog)
         		\ManiaLive\Utilities\Logger::getLog('runtime')->disableLog();*/
     } catch (\Exception $e) {
         // exception on startup ...
         ErrorHandling::processStartupException($e);
     }
 }
开发者ID:ketsuekiro,项目名称:manialive,代码行数:31,代码来源:AbstractApplication.php

示例14: execute

 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     declare (ticks=1);
     $this->output = $output;
     // Register shutdown function
     register_shutdown_function(array($this, 'stopCommand'));
     // Register SIGTERM/SIGINT catch if script is killed by user
     if (function_exists('pcntl_signal')) {
         pcntl_signal(SIGTERM, array($this, 'stopCommand'));
         pcntl_signal(SIGINT, array($this, 'stopCommand'));
     } else {
         $this->output->writeln('<options=bold>Note:</> The PHP function pcntl_signal isn\'t defined, which means you\'ll have to do some manual clean-up after using this command.');
         $this->output->writeln('Remove the file \'app/Mage.php.rej\' and the line \'Mage::log($name, null, \'n98-magerun-events.log\');\' from app/Mage.php after you\'re done.');
     }
     $this->detectMagento($output);
     if ($this->initMagento()) {
         $currentMagerunDir = dirname(__FILE__);
         $patch = $currentMagerunDir . '/0001-Added-logging-of-events.patch';
         // Enable logging & apply patch
         shell_exec('cd ' . \Mage::getBaseDir() . ' && n98-magerun.phar dev:log --on --global && patch -p1 < ' . $patch);
         $output->writeln('Tailing events... ');
         // Listen to log file
         shell_exec('echo "" > ' . \Mage::getBaseDir() . '/var/log/n98-magerun-events.log');
         $handle = popen('tail -f ' . \Mage::getBaseDir() . '/var/log/n98-magerun-events.log 2>&1', 'r');
         while (!feof($handle)) {
             $buffer = fgets($handle);
             $output->write($buffer);
             flush();
         }
         pclose($handle);
     }
 }
开发者ID:tuanphpvn,项目名称:magerun-addons,代码行数:37,代码来源:ListenCommand.php

示例15: initialize

 /**
  * 
  * @param InputInterface $input
  * @param OutputInterface $output
  * 
  * @return void
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     declare (ticks=1);
     pcntl_signal(SIGTERM, [$this, 'stopCommand']);
     pcntl_signal(SIGINT, [$this, 'stopCommand']);
 }
开发者ID:cimus,项目名称:gearman-bundle,代码行数:14,代码来源:RunWorkerCommand.php


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