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


PHP pcntl_wexitstatus函数代码示例

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


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

示例1: start

 /**
  * Start the child processes. 
  *
  * This should only be called from the command line. It should be called 
  * as early as possible during execution.
  *
  * This will return 'child' in the child processes. In the parent process, 
  * it will run until all the child processes exit or a TERM signal is 
  * received. It will then return 'done'.
  */
 public function start()
 {
     // Trap SIGTERM
     pcntl_signal(SIGTERM, array($this, 'handleTermSignal'), false);
     do {
         // Start child processes
         if ($this->procsToStart) {
             if ($this->forkWorkers($this->procsToStart) == 'child') {
                 return 'child';
             }
             $this->procsToStart = 0;
         }
         // Check child status
         $status = false;
         $deadPid = pcntl_wait($status);
         if ($deadPid > 0) {
             // Respond to child process termination
             unset($this->children[$deadPid]);
             if ($this->flags & self::RESTART_ON_ERROR) {
                 if (pcntl_wifsignaled($status)) {
                     // Restart if the signal was abnormal termination
                     // Don't restart if it was deliberately killed
                     $signal = pcntl_wtermsig($status);
                     if (in_array($signal, self::$restartableSignals)) {
                         echo "Worker exited with signal {$signal}, restarting\n";
                         $this->procsToStart++;
                     }
                 } elseif (pcntl_wifexited($status)) {
                     // Restart on non-zero exit status
                     $exitStatus = pcntl_wexitstatus($status);
                     if ($exitStatus > 0) {
                         echo "Worker exited with status {$exitStatus}, restarting\n";
                         $this->procsToStart++;
                     }
                 }
             }
             // Throttle restarts
             if ($this->procsToStart) {
                 usleep(500000);
             }
         }
         // Run signal handlers
         if (function_exists('pcntl_signal_dispatch')) {
             pcntl_signal_dispatch();
         } else {
             declare (ticks=1) {
                 $status = $status;
             }
         }
         // Respond to TERM signal
         if ($this->termReceived) {
             foreach ($this->children as $childPid => $unused) {
                 posix_kill($childPid, SIGTERM);
             }
             $this->termReceived = false;
         }
     } while (count($this->children));
     pcntl_signal(SIGTERM, SIG_DFL);
     return 'done';
 }
开发者ID:ruizrube,项目名称:spdef,代码行数:70,代码来源:ForkController.php

示例2: __construct

 public function __construct(callable $callBack = null)
 {
     $plug = \PMVC\plug(PLUGIN);
     $plug->log("Monitor starting.");
     while (empty($plug[IS_STOP_ALL]) || count($plug[CHILDREN])) {
         if (!empty($plug[MY_PARENT])) {
             break;
         }
         // Check for exited children
         $pid = pcntl_wait($status, WNOHANG);
         if (isset($plug[CHILDREN][$pid])) {
             $exitCode = pcntl_wexitstatus($status);
             $plug->log("Child {$pid} was stopped with exit code of {$exitCode}");
             if (!$plug[IS_STOP_ALL] && 1 !== $exitCode) {
                 $callbackId = $plug[CHILDREN][$pid];
                 $plug['start']->restore($callbackId);
             }
             $plug->cleanPid($pid);
         }
         pcntl_signal_dispatch();
         if (empty($plug[CHILDREN])) {
             $plug[IS_STOP_ALL] = true;
             break;
         }
         if ($callBack && empty($plug[IS_STOP_ALL])) {
             call_user_func($callBack);
         }
         // php will eat up your cpu if you don't have this
         usleep(50000);
         pcntl_signal_dispatch();
     }
     $plug->log("Monitor was exited.");
 }
开发者ID:pmvc-plugin,项目名称:supervisor,代码行数:33,代码来源:Monitor.php

示例3: childSignalHandler

 /**
  * Handler for process signals.
  *
  * @param int $signo
  * @param int $pid
  * @param int $status
  */
 public function childSignalHandler($signo = null, $pid = null, $status = null)
 {
     //If no pid is provided, that means we're getting the signal from the system.  Let's figure out
     //which child process ended
     if (!$pid) {
         $pid = pcntl_waitpid(-1, $status, WNOHANG);
     }
     //Make sure we get all of the exited children
     while ($pid > 0) {
         if ($pid && isset($this->currentJobs[$pid])) {
             $exitCode = pcntl_wexitstatus($status);
             if ($exitCode == 0) {
                 $this->logger->debug('TestCase was successful finished.', ['pid' => $pid]);
             } else {
                 $this->logger->info('Process exited with status != 0.', ['pid' => $pid, 'exitCode' => $exitCode]);
                 $this->exitCode = $exitCode;
             }
             unset($this->currentJobs[$pid]);
         } else {
             if ($pid) {
                 //Oh no, our job has finished before this parent process could even note that it had been launched!
                 //Let's make note of it and handle it when the parent process is ready for it
                 $this->logger->debug('Adding process to signal queue.', ['pid' => $pid]);
                 $this->signalQueue[$pid] = $status;
             }
         }
         $pid = pcntl_waitpid(-1, $status, WNOHANG);
     }
 }
开发者ID:komex,项目名称:unteist,代码行数:36,代码来源:MultiProcessor.php

示例4: child_signal_handler

 public function child_signal_handler($signo, $pid = null, $status = null)
 {
     //If no pid is provided, that means we're getting the signal from the system.  Let's figure out
     //which child process ended
     if (!$pid) {
         $pid = pcntl_waitpid(-1, $status, WNOHANG);
     }
     //Make sure we get all of the exited children
     while ($pid > 0) {
         if ($pid && isset($this->current_jobs[$pid])) {
             $exit_code = pcntl_wexitstatus($status);
             if ($exit_code != 0) {
                 echo "{$pid} exited with status " . $exit_code . "\n";
             }
             unset($this->current_jobs[$pid]);
         } else {
             if ($pid) {
                 //Oh no, our job has finished before this parent process could even note that it had been launched!
                 echo "..... Adding {$pid} to the signal queue ..... \n";
                 $this->signal_queue[$pid] = $status;
             }
         }
         $pid = pcntl_waitpid(-1, $status, WNOHANG);
     }
     return true;
 }
开发者ID:xiaoyjy,项目名称:retry,代码行数:26,代码来源:jobdaemon.php

示例5: getStatus

 public function getStatus($status)
 {
     if (pcntl_wifexited($status)) {
         return pcntl_wexitstatus($status);
     }
     return 1;
 }
开发者ID:josegonzalez,项目名称:Queue,代码行数:7,代码来源:PcntlHelper.php

示例6: run

 /**
  * run a callback in parrallel thread
  *
  * @param callable $callback
  * @return void
  */
 public function run(\Closure $callback = null)
 {
     $callback = $callback ?: function () {
     };
     $children = array();
     while (!empty($this->works)) {
         $items = array_pop($this->works);
         $pid = pcntl_fork();
         if (-1 == $pid) {
             throw new \RuntimeException('無法使用子程序!');
         } elseif ($pid) {
             //子程序start
             $children[] = $pid;
             $this->onStart($pid);
         } else {
             try {
                 //子程序處理 callback
                 $callback($items);
                 exit(0);
             } catch (\Exception $e) {
                 exit($e->getCode());
             }
         }
     }
     if ($children) {
         foreach ($children as $child) {
             $res = pcntl_waitpid($child, $status);
             if ($res == -1 || $res > 0) {
                 //子程序end
                 $status = pcntl_wexitstatus($status);
                 $this->onExit($child, $status);
             }
         }
     }
 }
开发者ID:bigsai95,项目名称:php-thread,代码行数:41,代码来源:Forker.php

示例7: waitForBackground

 protected function waitForBackground(InputInterface $input, OutputInterface $output)
 {
     $lastMemory = memory_get_usage(true);
     while (true) {
         $memory = memory_get_usage(true);
         if ($memory != $lastMemory) {
             $output->writeln(sprintf("memory change: %d, from %d to %d", $memory - $lastMemory, $lastMemory, $memory));
         }
         $lastMemory = $memory;
         $status = 0;
         $pid = pcntl_waitpid(-1, $status, WNOHANG);
         if ($pid == 0) {
             // no child process has quit
             //usleep(200 * 1000);
         } else {
             if ($pid > 0) {
                 // child process with pid = $pid exits
                 $exitStatus = pcntl_wexitstatus($status);
                 $this->onChildProcessExit($pid, $exitStatus, $input, $output);
             } else {
                 // error
                 $errno = pcntl_get_last_error();
                 if ($errno == PCNTL_ECHILD) {
                     // all children finished
                     mdebug("No more BackgroundProcessRunner children, continue ...");
                     break;
                 } else {
                     // some other error
                     throw new \RuntimeException("Error waiting for process, error = " . pcntl_strerror($errno));
                 }
             }
         }
     }
     return $this->isFailed ? self::EXIT_CODE_COMMON_ERROR : self::EXIT_CODE_OK;
 }
开发者ID:oasmobile,项目名称:php-slimapp,代码行数:35,代码来源:AbstractParallelCommand.php

示例8: excute

function excute($url = '', $data)
{
    connectRedis();
    $response = array();
    $loop = count($data);
    for ($i = 0; $i < $loop; $i++) {
        # code...
        $pid = pcntl_fork();
        if (!$pid) {
            // sleep(1);
            print "In child {$i}\n";
            if (array_key_exists($i, $data)) {
                $x = 7;
                $k = get_url($data[$i]);
                setRedis("data", $i);
            }
            exit($i);
        }
    }
    #process
    while (pcntl_waitpid(0, $status) != -1) {
        $status = pcntl_wexitstatus($status);
        echo "Child {$status} completed\n";
    }
    // dd($response);
    return $response;
}
开发者ID:maxca,项目名称:Multiple-processing-php,代码行数:27,代码来源:Multiprocessing-php-with-redis.php

示例9: onChildExit

 protected function onChildExit($pid, $status)
 {
     $workerId = -1;
     foreach ($this->workers as $k => $worker) {
         if ($pid == $worker->getPid()) {
             $workerId = $k;
             break;
         }
     }
     if ($workerId == -1) {
         throw new RuntimeException('unknown child pid');
     }
     if ($this->gotTerm) {
         $this->workers[$workerId]->callFromMasterOnTerm($status);
         unset($this->workers[$workerId]);
         return;
     }
     if (pcntl_wifexited($status) && 0 == pcntl_wexitstatus($status)) {
         $this->workers[$workerId]->callFromMasterOnSuccess($status);
         unset($this->workers[$workerId]);
         return;
     }
     $this->workers[$workerId]->callFromMasterOnError($status);
     $this->internalSpawnWorker($this->workers[$workerId]);
 }
开发者ID:renwuxun,项目名称:phpserver,代码行数:25,代码来源:Master.php

示例10: run

 /**
  * 执行同步
  * @return bool
  */
 public function run()
 {
     while (1) {
         $online_user = $this->get_data('Online')->get_online_list();
         $user_num = count($online_user);
         if (empty($online_user)) {
             sleep($this->_set_interval_time);
             #等待一下
             break;
         }
         $threads = array();
         foreach ($this->_sync_tables as $table) {
             $pid = pcntl_fork();
             if ($pid == -1) {
                 echo "FORK ERROR \n";
                 return false;
             } else {
                 if ($pid) {
                     $threads[] = $pid;
                     echo "CREATE THREAD SUCESS CUR THREAD ID IS {$pid}\n";
                 } else {
                     $exec_starttime = microtime(true);
                     $this->sync($online_user, $table);
                     echo "syncdb {$user_num} execute {$table['table_name']} func run " . (microtime(true) - $exec_starttime) . "\n";
                     exit(1);
                 }
             }
         }
         /*
         			foreach($this->_sync_union as $union_table){
                         $pid = pcntl_fork();
                         if($pid == -1){
                             echo "FORK ERROR \n";
                             return false;
                         }else{
                             if($pid){
                                 $threads[] = $pid;
                                 echo "CREATE THREAD SUCESS CUR THREAD ID IS {$pid}\n";
                             }else{
                                 $exec_starttime = microtime(true);
                                 $this->sync_union($online_user,$union_table);
                                 echo "syncdb {$user_num} execute {$union_table['table_name']} func run ".(microtime(true)-$exec_starttime)."\n";
                                 exit(1);
                             }
                         }
                     }*/
         foreach ($threads as $thread_id) {
             pcntl_waitpid($thread_id, $status);
             echo "THREAD {$thread_id} NOW EXIT\n";
             if (pcntl_wifexited($status)) {
                 $c = pcntl_wexitstatus($status);
                 echo "CHILD EXIT PID {$thread_id} STATUS {$c}\n";
             }
         }
         echo "SyncDb SUCESS\n";
         sleep($this->_set_interval_time);
         #等待一下
     }
 }
开发者ID:bluefan,项目名称:phpsource,代码行数:63,代码来源:SyncDb.php

示例11: exitStatusOfLastChild

 private function exitStatusOfLastChild($status)
 {
     $exitStatusOfLastChild = pcntl_wexitstatus($status);
     $lastChildExitedNormally = pcntl_wifexited($status);
     if ($exitStatusOfLastChild === 0 && !$lastChildExitedNormally) {
         $exitStatusOfLastChild = 1;
     }
     return $exitStatusOfLastChild;
 }
开发者ID:gabrielelana,项目名称:graceful-death,代码行数:9,代码来源:GracefulDeath.php

示例12: isCompleted

 /**
  * @return bool
  */
 public function isCompleted()
 {
     $pid = pcntl_waitpid($this->getPid(), $status, WNOHANG);
     if ($pid == -1 || $pid === $this->getPid()) {
         $this->status = pcntl_wexitstatus($status);
         return true;
     }
     return false;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:12,代码来源:Process.php

示例13: join

 /**
  * Wait for the background process to exit
  */
 public function join()
 {
     if ($this->_started) {
         $status = null;
         pcntl_waitpid($this->_childPid, $status);
         $this->_started = false;
         $this->_returnCode = pcntl_wexitstatus($status);
     }
     return $this->_returnCode;
 }
开发者ID:packaged,项目名称:console,代码行数:13,代码来源:BackgroundProcess.php

示例14: start

 /**
  * Start a thread
  */
 public function start()
 {
     $this->fork();
     if (!$this->pid) {
         $this->run();
         if (substr(PHP_SAPI, 0, 3) == 'cli') {
             exit;
         }
         pcntl_wexitstatus(null);
     }
 }
开发者ID:tiagobutzke,项目名称:phparallel,代码行数:14,代码来源:Thread.php

示例15: pleac_Running_Another_Program

function pleac_Running_Another_Program()
{
    // Run a simple command and retrieve its result code.
    exec("vi {$myfile}", $output, $result_code);
    // -----------------------------
    // Use the shell to perform redirection.
    exec('cmd1 args | cmd2 | cmd3 >outfile');
    exec('cmd args <infile >outfile 2>errfile');
    // -----------------------------
    // Run a command, handling its result code or signal.
    $pid = pcntl_fork();
    if ($pid == -1) {
        die('cannot fork');
    } elseif ($pid) {
        pcntl_waitpid($pid, $status);
        if (pcntl_wifexited($status)) {
            $status = pcntl_wexitstatus($status);
            echo "program exited with status {$status}\n";
        } elseif (pcntl_wifsignaled($status)) {
            $signal = pcntl_wtermsig($status);
            echo "program killed by signal {$signal}\n";
        } elseif (pcntl_wifstopped($status)) {
            $signal = pcntl_wstopsig($status);
            echo "program stopped by signal {$signal}\n";
        }
    } else {
        pcntl_exec($program, $args);
    }
    // -----------------------------
    // Run a command while blocking interrupt signals.
    $pid = pcntl_fork();
    if ($pid == -1) {
        die('cannot fork');
    } elseif ($pid) {
        // parent catches INT and berates user
        declare (ticks=1);
        function handle_sigint($signal)
        {
            echo "Tsk tsk, no process interruptus\n";
        }
        pcntl_signal(SIGINT, 'handle_sigint');
        while (!pcntl_waitpid($pid, $status, WNOHANG)) {
        }
    } else {
        // child ignores INT and does its thing
        pcntl_signal(SIGINT, SIG_IGN);
        pcntl_exec('/bin/sleep', array('10'));
    }
    // -----------------------------
    // Since there is no direct access to execv() and friends, and
    // pcntl_exec() won't let us supply an alternate program name
    // in the argument list, there is no way to run a command with
    // a different name in the process table.
}
开发者ID:Halfnhav4,项目名称:pfff,代码行数:54,代码来源:Running_Another_Program.php


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