當前位置: 首頁>>代碼示例>>PHP>>正文


PHP pcntl_alarm函數代碼示例

本文整理匯總了PHP中pcntl_alarm函數的典型用法代碼示例。如果您正苦於以下問題:PHP pcntl_alarm函數的具體用法?PHP pcntl_alarm怎麽用?PHP pcntl_alarm使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了pcntl_alarm函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: minecraft_command

function minecraft_command($signal)
{
    global $_CONFIG, $_STATE;
    switch ($signal) {
        case SIGHUP:
            logmsg("SIGHUP - reload");
            $command = 'reload';
            break;
        case SIGUSR1:
            logmsg("SIGUSR1 - save-on");
            $command = 'save-on';
            break;
        case SIGUSR2:
            logmsg("SIGUSR2 - save-off");
            $command = 'save-off';
            break;
        case SIGALRM:
            logmsg("SIGALRM - save-all");
            $command = 'save-all';
            if (isset($_CONFIG['AlarmInterval'])) {
                pcntl_alarm($_CONFIG['AlarmInterval']);
            }
            break;
    }
    fwrite($_STATE['Descriptors'][0], $command . PHP_EOL);
    fflush($_STATE['Descriptors'][0]);
}
開發者ID:haxney,項目名稱:minecraft-config,代碼行數:27,代碼來源:daemonize_minecraft.php

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

示例3: beat

 public function beat()
 {
     if (false === $this->stopped) {
         pcntl_alarm((int) 1);
         $this->tick();
     }
 }
開發者ID:romainneutron,項目名稱:Tip-Top,代碼行數:7,代碼來源:Pulse.php

示例4: signalHandler

 /**
  * Signal handler
  * 
  * @param  int $signalNumber
  * @return void
  */
 public function signalHandler($signalNumber)
 {
     echo 'Handling signal: #' . $signalNumber . PHP_EOL;
     global $consumer;
     switch ($signalNumber) {
         case SIGTERM:
             // 15 : supervisor default stop
         // 15 : supervisor default stop
         case SIGQUIT:
             // 3  : kill -s QUIT
             $consumer->stopHard();
             break;
         case SIGINT:
             // 2  : ctrl+c
             $consumer->stop();
             break;
         case SIGHUP:
             // 1  : kill -s HUP
             $consumer->restart();
             break;
         case SIGUSR1:
             // 10 : kill -s USR1
             // send an alarm in 1 second
             pcntl_alarm(1);
             break;
         case SIGUSR2:
             // 12 : kill -s USR2
             // send an alarm in 10 seconds
             pcntl_alarm(10);
             break;
         default:
             break;
     }
     return;
 }
開發者ID:CarsonF,項目名稱:php-amqplib,代碼行數:41,代碼來源:amqp_consumer_signals.php

示例5: setSigAlarm

 protected function setSigAlarm()
 {
     pcntl_signal(SIGALRM, array(&$this, 'sigAlarmCallback'));
     $sec = $this->getSigAlarmTimeout();
     if ($sec > -1) {
         pcntl_alarm($this->getSigAlarmTimeout());
     }
 }
開發者ID:ketheriel,項目名稱:ETVA,代碼行數:8,代碼來源:etvaBaseTask.class.php

示例6: setupDaemon

 /**
  * Loads to configuration from the daemon options and installs signal
  * handlers.
  *
  * @param DaemonOptions $daemonOptions
  */
 private function setupDaemon(DaemonOptions $daemonOptions)
 {
     $this->requestCount = 0;
     $this->requestLimit = $daemonOptions->getOption(DaemonOptions::REQUEST_LIMIT);
     $this->memoryLimit = $daemonOptions->getOption(DaemonOptions::MEMORY_LIMIT);
     $timeLimit = $daemonOptions->getOption(DaemonOptions::TIME_LIMIT);
     if (DaemonOptions::NO_LIMIT !== $timeLimit) {
         pcntl_alarm($timeLimit);
     }
     $this->installSignalHandlers();
 }
開發者ID:sojimaxi,項目名稱:FastCGIDaemon,代碼行數:17,代碼來源:DaemonTrait.php

示例7: testStreamSelectSignalInterrupt

 /**
  * Test stream_select signal interrupt doesn't trigger \RunTime exception.
  */
 public function testStreamSelectSignalInterrupt()
 {
     $address = 'tcp://localhost:7000';
     $serverSocket = stream_socket_server($address);
     $connectionPool = new StreamSocketConnectionPool($serverSocket);
     $alarmCalled = false;
     declare (ticks=1);
     pcntl_signal(SIGALRM, function () use(&$alarmCalled) {
         $alarmCalled = true;
     });
     pcntl_alarm(1);
     $connectionPool->getReadableConnections(2);
     $this->assertTrue($alarmCalled);
 }
開發者ID:sojimaxi,項目名稱:FastCGIDaemon,代碼行數:17,代碼來源:StreamSocketConnectionPoolTest.php

示例8: setUp

 public function setUp()
 {
     // Make this process a session leader so we can send signals
     // to this job as a whole (including any subprocesses such as spawned by Symfony).
     posix_setsid();
     if (function_exists('pcntl_alarm') && function_exists('pcntl_signal')) {
         if (!empty($this->args['sigFile'])) {
             echo sprintf('[-] Signal file requested, polling "%s".' . PHP_EOL, $this->args['sigFile']);
             declare (ticks=1);
             pcntl_signal(SIGALRM, [$this, 'alarmHandler']);
             pcntl_alarm(1);
         }
     }
     $this->updateStatus(DNDeployment::TR_DEPLOY);
     chdir(BASE_PATH);
 }
開發者ID:silverstripe,項目名稱:deploynaut,代碼行數:16,代碼來源:DeployJob.php

示例9: pleac_Timing_Out_an_Operation

function pleac_Timing_Out_an_Operation()
{
    declare (ticks=1);
    $aborted = false;
    function handle_alarm($signal)
    {
        global $aborted;
        $aborted = true;
    }
    pcntl_signal(SIGALRM, 'handle_alarm');
    pcntl_alarm(3600);
    // long-time operations here
    pcntl_alarm(0);
    if ($aborted) {
        // timed out - do what you will here
    }
}
開發者ID:Halfnhav4,項目名稱:pfff,代碼行數:17,代碼來源:Timing_Out_an_Operation.php

示例10: invoke

 /**
  * Invokes a callable and raises an exception when the execution does not
  * finish before the specified timeout.
  *
  * @param  callable                 $callable
  * @param  array                    $arguments
  * @param  int                      $timeout   in seconds
  * @return mixed
  * @throws InvalidArgumentException
  */
 public function invoke($callable, array $arguments, $timeout)
 {
     if (!is_callable($callable)) {
         throw new InvalidArgumentException();
     }
     if (!is_integer($timeout)) {
         throw new InvalidArgumentException();
     }
     pcntl_signal(SIGALRM, array($this, 'callback'), TRUE);
     pcntl_alarm($timeout);
     $this->timeout = $timeout;
     try {
         $result = call_user_func_array($callable, $arguments);
     } catch (Exception $e) {
         pcntl_alarm(0);
         throw $e;
     }
     pcntl_alarm(0);
     return $result;
 }
開發者ID:AndyDune,項目名稱:rzn.phpunit4,代碼行數:30,代碼來源:Invoker.php

示例11: run

 /**
  * Executes a callable until a timeout is reached or the callable returns `true`.
  *
  * @param  Callable $callable The callable to execute.
  * @param  integer  $timeout  The timeout value.
  * @return mixed
  */
 public static function run($callable, $timeout = 0)
 {
     if (!is_callable($callable)) {
         throw new InvalidArgumentException();
     }
     $timeout = (int) $timeout;
     if (!function_exists('pcntl_signal')) {
         throw new Exception("PCNTL threading is not supported on your OS.");
     }
     pcntl_signal(SIGALRM, function ($signal) use($timeout) {
         throw new TimeoutException("Timeout reached, execution aborted after {$timeout} second(s).");
     }, true);
     pcntl_alarm($timeout);
     $result = null;
     try {
         $result = $callable();
     } catch (Exception $e) {
         throw $e;
     } finally {
         pcntl_alarm(0);
     }
     return $result;
 }
開發者ID:crysalead,項目名稱:code,代碼行數:30,代碼來源:Code.php

示例12: add

 /**
  * 
  * 添加一個任務
  * 
  * @param int $time_long 多長時間運行一次 單位秒
  * @param callback $func 任務運行的函數或方法
  * @param mix $args 任務運行的函數或方法使用的參數
  * @return void
  */
 public static function add($time_long, $func, $args = array(), $persistent = true)
 {
     if ($time_long <= 0) {
         return false;
     }
     if (!is_callable($func)) {
         if (class_exists('\\Man\\Core\\Lib\\Log')) {
             \Man\Core\Lib\Log::add(var_export($func, true) . "not callable\n");
         }
         return false;
     }
     // 有任務時才出發計時器
     if (empty(self::$tasks)) {
         pcntl_alarm(1);
     }
     $time_now = time();
     $run_time = $time_now + $time_long;
     if (!isset(self::$tasks[$run_time])) {
         self::$tasks[$run_time] = array();
     }
     self::$tasks[$run_time][] = array($func, $args, $persistent, $time_long);
     return true;
 }
開發者ID:walkor,項目名稱:workerman-bench,代碼行數:32,代碼來源:Task.php

示例13: run

 /**
  * 運行守護進程,監控有變化的日誌文件。
  * 
  * @see ZtChart_Model_Monitor_Abstract::daemon()
  */
 public function run()
 {
     if (0 == ($pid = pcntl_fork())) {
         // 子進程負責處理當前日誌
         try {
             $this->tail($this->_console->getLogPaths());
         } catch (ZtChart_Model_Monitor_Exception $e) {
             $this->_logger->err($e->getMessage());
             exit(1);
         }
     } else {
         if (0 < $pid) {
             pcntl_setpriority(-1);
             // 父進程負責把子進產生的數據寫入數據庫
             if (pcntl_sigprocmask(SIG_BLOCK, array(SIGCHLD, SIGALRM, SIGINT, SIGTERM))) {
                 $interval = 10;
                 // 10秒寫一次
                 pcntl_alarm($interval);
                 while ($signo = pcntl_sigwaitinfo(array(SIGCHLD, SIGALRM, SIGINT, SIGTERM))) {
                     if (SIGALRM == $signo) {
                         pcntl_alarm($interval);
                     }
                     try {
                         $this->extract($interval);
                     } catch (ZtChart_Model_Monitor_Exception $e) {
                         posix_kill($pid, 9);
                         exit(1);
                     }
                     if (SIGCHLD == $signo || SIGINT == $signo || SIGTERM == $signo) {
                         break;
                     }
                 }
             }
         }
     }
     exit(0);
 }
開發者ID:starflash,項目名稱:ZtChart-ZF1-Example,代碼行數:42,代碼來源:Realtime.php

示例14: delAll

 /**
  * Remove all timers.
  * @return void
  */
 public static function delAll()
 {
     self::$_tasks = array();
     pcntl_alarm(0);
     if (self::$_event) {
         self::$_event->clearAllTimer();
     }
 }
開發者ID:TongJiankang,項目名稱:Workerman,代碼行數:12,代碼來源:Timer.php

示例15: recvInnerTcp

 /**
  * 處理內部通訊收到的數據
  * @param event_buffer $event_buffer
  * @param int $fd
  * @return void
  */
 public function recvInnerTcp($connection, $flag, $fd = null)
 {
     $this->currentDealFd = $fd;
     $buffer = stream_socket_recvfrom($connection, $this->recvBuffers[$fd]['remain_len']);
     // 出錯了
     if ('' == $buffer && '' == ($buffer = fread($connection, $this->recvBuffers[$fd]['remain_len']))) {
         // 判斷是否是鏈接斷開
         if (!feof($connection)) {
             return;
         }
         // 如果該鏈接對應的buffer有數據,說明發生錯誤
         if (!empty($this->recvBuffers[$fd]['buf'])) {
             $this->statusInfo['send_fail']++;
         }
         // 關閉鏈接
         $this->closeInnerClient($fd);
         $this->notice("CLIENT:" . $this->getRemoteIp() . " CLOSE INNER_CONNECTION\n");
         if ($this->workerStatus == self::STATUS_SHUTDOWN) {
             $this->stop();
         }
         return;
     }
     $this->recvBuffers[$fd]['buf'] .= $buffer;
     $remain_len = $this->dealInnerInput($this->recvBuffers[$fd]['buf']);
     // 包接收完畢
     if (0 === $remain_len) {
         // 內部通訊業務處理
         $this->innerDealProcess($this->recvBuffers[$fd]['buf']);
         $this->recvBuffers[$fd] = array('buf' => '', 'remain_len' => GatewayProtocol::HEAD_LEN);
     } else {
         if (false === $remain_len) {
             // 出錯
             $this->statusInfo['packet_err']++;
             $this->notice("INNER_PACKET_ERROR and CLOSE_INNER_CONNECTION\nCLIENT_IP:" . $this->getRemoteIp() . "\nBUFFER:[" . bin2hex($this->recvBuffers[$fd]['buf']) . "]\n");
             $this->closeInnerClient($fd);
         } else {
             $this->recvBuffers[$fd]['remain_len'] = $remain_len;
         }
     }
     // 檢查是否是關閉狀態或者是否到達請求上限
     if ($this->workerStatus == self::STATUS_SHUTDOWN) {
         // 停止服務
         $this->stop();
         // EXIT_WAIT_TIME秒後退出進程
         pcntl_alarm(self::EXIT_WAIT_TIME);
     }
 }
開發者ID:shitfSign,項目名稱:workerman-MT,代碼行數:53,代碼來源:Gateway.php


注:本文中的pcntl_alarm函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。