• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP pcntl_wifexited函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了pcntl_wifexited函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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;
     }
 }
开发者ID:hofmeister,项目名称:Pimple,代码行数:27,代码来源:Thread.php


示例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]);
 }
开发者ID:renwuxun,项目名称:phpserver,代码行数:25,代码来源:Master.php


示例4: getStatus

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


示例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);
     }
 }
开发者ID:sergeypavlenko,项目名称:queue,代码行数:34,代码来源:worker.php


示例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);
         #等待一下
     }
 }
开发者ID:bluefan,项目名称:phpsource,代码行数:63,代码来源:SyncDb.php


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


示例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.
}
开发者ID:Halfnhav4,项目名称:pfff,代码行数:54,代码来源:Running_Another_Program.php


示例9: __construct

 /**
  * Analyzes the passed status code of a process and sets properties accordingly.
  * 
  * @param int $status
  * @author Dan Homorodean <[email protected]>
  */
 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);
     }
 }
开发者ID:dan-homorodean,项目名称:falx-concurrency-and-ipc,代码行数:19,代码来源:ProcessStatus.php


示例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');
 }
开发者ID:Halfnhav4,项目名称:pfff,代码行数:15,代码来源:Avoiding_Zombie_Processes.php


示例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);
        }
    }
}
开发者ID:badlamer,项目名称:hhvm,代码行数:15,代码来源:001.php


示例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}";
        }
    }
}
开发者ID:ezc,项目名称:Toolkit,代码行数:21,代码来源:fork.php


示例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);
 }
开发者ID:xiaoyjy,项目名称:retry,代码行数:41,代码来源:main.php


示例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";
    }
}
开发者ID:yegking,项目名称:zhihuSpider,代码行数:31,代码来源:get_user_info.php


示例15: isExited

 public function isExited()
 {
     return null !== $this->status && pcntl_wifexited($this->status);
 }
开发者ID:channelgrabber,项目名称:spork,代码行数:4,代码来源:Fork.php


示例16: pcntl_fork

        if ($stream === $server && count($children) < 2) {
            $conn = @stream_socket_accept($server, -1, $peer);
            if (!is_resource($conn)) {
                continue;
            }
            echo "Starting a new child process for {$peer}\n";
            $pid = pcntl_fork();
            if ($pid > 0) {
                $children[] = $pid;
            } elseif ($pid === 0) {
                // Child process, implement our echo server
                $childPid = posix_getpid();
                fwrite($conn, "You are connected to process {$childPid}\n");
                while ($buf = fread($conn, 4096)) {
                    fwrite($conn, $buf);
                }
                fclose($conn);
                // We are done, quit.
                exit(0);
            }
        }
    }
    // Do housekeeping on exited childs
    foreach ($children as $i => $child) {
        $result = pcntl_waitpid($child, $status, WNOHANG);
        if ($result > 0 && pcntl_wifexited($status)) {
            unset($children[$i]);
        }
    }
    echo "\t" . count($children) . " connected\r";
}
开发者ID:timsims,项目名称:book-examples,代码行数:31,代码来源:limited_forking_echo_server.php


示例17: stop

 /**
  * Causes the current thread to die.
  *
  * The relative process is killed and disappears immediately from the
  * processes list.
  *
  * @return boolean
  */
 public function stop()
 {
     $success = false;
     if ($this->_pid > 0) {
         $status = 0;
         posix_kill($this->_pid, 9);
         pcntl_waitpid($this->_pid, $status, WNOHANG);
         $success = pcntl_wifexited($status);
         $this->_cleanProcessContext();
     }
     return $success;
 }
开发者ID:jkimdon,项目名称:cohomeals,代码行数:20,代码来源:Unix.php


示例18: send_mail_sendmail

 protected function send_mail_sendmail($from, $to, $subject, $hdr, $body)
 {
     $cmd = escapeshellcmd(conf('mail.sendmail.path')) . ' -t -i -f ' . escapeshellarg($from);
     // $cmd = escapeshellcmd(conf('mail.sendmail.path')) . ' -t -i';
     $h = popen($cmd, 'w');
     if (!$h) {
         return "SENDMAIL: can't open pipe ({$cmd})";
     }
     fputs($h, $hdr);
     fputs($h, $body);
     $stat = pclose($h);
     if (function_exists('pcntl_wifexited')) {
         if (!pcntl_wifexited($stat)) {
             return 'SENDMAIL: abnormal sendmail process terminate';
         }
         $res = pcntl_wexitstatus($stat);
     } else {
         if (version_compare(phpversion(), '4.2.3') == -1) {
             $res = $stat >> 8 & 0xff;
         } else {
             $res = $stat;
         }
     }
     if ($res) {
         return "SENDMAIL: error occurred (cmd: {$cmd}) (code: {$res})";
     }
     return '';
 }
开发者ID:restorer,项目名称:deprecated-s-imple-php-framework,代码行数:28,代码来源:email.php


示例19: isSuccessExit

 /**
  * Check exit code and return TRUE if process was ended successfully.
  *
  * @return bool
  */
 public function isSuccessExit()
 {
     $this->exitCode = pcntl_wexitstatus($this->status);
     return pcntl_wifexited($this->status) && $this->exitCode === 0;
 }
开发者ID:meckhardt,项目名称:ko-process,代码行数:10,代码来源:Process.php


示例20: isNormalExit

 public function isNormalExit() : bool
 {
     return pcntl_wifexited($this->getStatus());
 }
开发者ID:ThrusterIO,项目名称:process-exit-handler,代码行数:4,代码来源:ExitEvent.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP pcntl_wifsignaled函数代码示例发布时间:2022-05-15
下一篇:
PHP pcntl_wexitstatus函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap