forkOneWorker 创建进程后又退出

lh
protected static function forkOneWorker($worker)
    {
        // Get available worker id.
        $id = self::getId($worker->workerId, 0);
        if ($id === false) {
            return;
        }
        $pid = pcntl_fork();
        // For master process.
        if ($pid > 0) {
            self::$_pidMap = $pid;
            self::$_idMap   = $pid;
        } // For child processes.
        elseif (0 === $pid) {
            if ($worker->reusePort) {
                $worker->listen();
            }
            if (self::$_status === self::STATUS_STARTING) {
                self::resetStd();
            }
            self::$_pidMap  = array();
            self::$_workers = array($worker->workerId => $worker);
            Timer::delAll();
            self::setProcessTitle('WorkerMan: worker process  ' . $worker->name . ' ' . $worker->getSocketName());
            $worker->setUserAndGroup();
            $worker->id = $id;
            $worker->run();
            exit(250);
        } else {
            throw new Exception("forkOneWorker fail");
        }
    }

如上,后面为什么要 exit(250)呢

6167 1 0
1个回答

walkor 打赏

子进程会阻塞在$worker->run();不会执行到 exit(250);。

为了保险,在$worker->run();加了一行exit(250)

  • 暂无评论
年代过于久远,无法发表回答
×
🔝