本文整理汇总了PHP中pcntl_wifexited函数的典型用法代码示例。如果您正苦于以下问题:PHP pcntl_wifexited函数的具体用法?PHP pcntl_wifexited怎么用?PHP pcntl_wifexited使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pcntl_wifexited函数的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';
}
示例2: execute
public final function execute()
{
$hasThreads = function_exists('pcntl_signal');
if (!$hasThreads || Cli::getInstance()->isSimulation()) {
flush();
try {
return $this->executeNoThread();
} catch (Interrupt $e) {
throw $e;
} catch (Exception $e) {
echo $e;
}
return;
}
pcntl_signal(SIGCHLD, SIG_IGN);
$pid = pcntl_fork();
if ($pid < 1) {
$this->_run();
posix_kill(posix_getpid(), 9);
pcntl_waitpid(posix_getpid(), $temp = 0, WNOHANG);
pcntl_wifexited($temp);
exit;
//Make sure we exit...
} else {
$this->pid = $pid;
}
}
示例3: 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]);
}
示例4: getStatus
public function getStatus($status)
{
if (pcntl_wifexited($status)) {
return pcntl_wexitstatus($status);
}
return 1;
}
示例5: process
private function process()
{
$messageType = NULL;
$messageMaxSize = 1024;
while (TRUE) {
if (count($this->childs) < $this->max) {
echo count($this->childs) . " ";
if (msg_receive($this->queue, QUEUE_TYPE_START, $messageType, $messageMaxSize, $this->message)) {
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork' . PHP_EOL);
} else {
if ($pid) {
$this->childs[$pid] = TRUE;
$messageType = NULL;
$this->message = NULL;
} else {
sleep(3);
$this->complete($messageType, $this->message);
exit;
}
}
foreach ($this->childs as $pid => $value) {
if (pcntl_waitpid($pid, $status, WNOHANG)) {
if (pcntl_wifexited($status)) {
unset($this->childs[$pid]);
}
}
}
}
}
sleep(1);
}
}
示例6: 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);
#等待一下
}
}
示例7: exitStatusOfLastChild
private function exitStatusOfLastChild($status)
{
$exitStatusOfLastChild = pcntl_wexitstatus($status);
$lastChildExitedNormally = pcntl_wifexited($status);
if ($exitStatusOfLastChild === 0 && !$lastChildExitedNormally) {
$exitStatusOfLastChild = 1;
}
return $exitStatusOfLastChild;
}
示例8: 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.
}
示例9: __construct
/**
* Analyzes the passed status code of a process and sets properties accordingly.
*
* @param int $status
* @author Dan Homorodean <dan.homorodean@gmail.com>
*/
public function __construct($status)
{
if (pcntl_wifexited($status)) {
$this->status = self::STATUS_EXITED;
$this->exitCode = pcntl_wexitstatus($status);
} elseif (pcntl_wifsignaled($status)) {
$this->status = self::STATUS_SIGNALED;
$this->reasonSignal = pcntl_wtermsig($status);
} elseif (pcntl_wifstopped($status)) {
$this->status = self::STATUS_STOPPED;
$this->reasonSignal = pcntl_wstopsig($status);
}
}
示例10: reaper
function reaper($signal)
{
$pid = pcntl_waitpid(-1, $status, WNOHANG);
if ($pid == -1) {
// No child waiting. Ignore it.
} else {
if (pcntl_wifexited($signal)) {
echo "Process {$pid} exited.\n";
} else {
echo "False alarm on {$pid}\n";
}
reaper($signal);
}
pcntl_signal(SIGCHLD, 'reaper');
}
示例11: test_exit_waits
function test_exit_waits()
{
print "\n\nTesting pcntl_wifexited and wexitstatus....";
$pid = pcntl_fork();
if ($pid == 0) {
sleep(1);
exit(-1);
} else {
$options = 0;
pcntl_waitpid($pid, $status, $options);
if (pcntl_wifexited($status)) {
print "\nExited With: " . pcntl_wexitstatus($status);
}
}
}
示例12: process_execute
function process_execute($input)
{
$pid = pcntl_fork();
//创建子进程
if ($pid == 0) {
//子进程进入了这个岔路口,父进程直接执行if后面的代码
$pid = posix_getpid();
echo "* Process {$pid} was created, and Executed:\n\n";
eval($input);
//解析命令
exit;
//子进程必须退出,否则还会继续执行if后面的代码
} else {
//主进程
$pid = pcntl_wait($status, WUNTRACED);
//取得子进程结束状态
if (pcntl_wifexited($status)) {
echo "\n\n* Sub process: {$pid} exited with {$status}";
}
}
}
示例13: worker_onexit
function worker_onexit($pw, $revents)
{
cy_log(CYE_DEBUG, "in worker_onexit");
if (!is_object($pw) && get_class($pw) !== 'EvChild') {
cy_log(CYE_ERROR, 'error type param, in worker_onexit');
return;
}
$pw->stop();
$pid = $pw->rpid;
pcntl_waitpid($pid, $status, WNOHANG);
$wiexit = pcntl_wifexited($status);
$status = $pw->rstatus;
$worker = $this->workers[$pid];
$key = $worker['key'];
unset($this->workers[$pid]);
if ($this->flag === WKST_RUNNING || $this->flag === WKST_SPAWN) {
$this->worker_fork($key);
} elseif ($this->flag === WKST_END) {
$now_num = cy_i_get('bps_srv_' . $key . '_num', CY_TYPE_SYS);
if ($now_num === 0) {
$this->loop->stop();
}
}
cy_i_dec("bps_srv_" . $key . "_num", CY_TYPE_SYS, 1);
cy_i_del("bps_srv_lock_" . $pid, CY_TYPE_SYS);
if ($wiexit) {
return;
}
/* 子进程没有正常退出, 加保护性代码,防止进程因为被kill而死锁 */
if ($flag === WKST_QUITING) {
cy_log(CYE_TRACE, $pid . ' exit, receive master cmd.');
} else {
cy_log(CYE_ERROR, $pid . ' is not normal exited.');
}
// TCP Server Only
$stat_lock = cy_i_get($stat_name, CY_TYPE_SYS);
if ($stat_lock) {
cy_unlock('bps_' . $key . '_lock');
}
usleep(100000);
}
示例14: foreach
if (!empty($follower_users)) {
foreach ($follower_users as $user) {
$tmp_redis->lpush('request_queue', $user[1]);
}
}
Log::info('empty follower_users u_id' . $tmp_u_id);
echo "--------get " . count($follower_users) . " followers users done--------\n";
}
$tmp_redis->zadd('already_get_queue', 1, $tmp_u_id);
$tmp_redis->close();
$endTime = microtime();
$startTime = explode(' ', $startTime);
$endTime = explode(' ', $endTime);
$total_time = $endTime[0] - $startTime[0] + $endTime[1] - $startTime[1];
$timecost = sprintf("%.2f", $total_time);
echo "--------const " . $timecost . " second on {$tmp_u_id}--------\n";
} else {
echo "--------user {$tmp_u_id} info and followee and follower already get--------\n";
}
exit($i);
}
usleep(1);
}
while (pcntl_waitpid(0, $status) != -1) {
$status = pcntl_wexitstatus($status);
if (pcntl_wifexited($status)) {
echo "yes";
}
echo "--------{$status} finished--------\n";
}
}
示例15: isExited
public function isExited()
{
return null !== $this->status && pcntl_wifexited($this->status);
}