php - WebSocket,pcntl_fork,正确关闭子进程

时间:2014-12-07 13:54:43

标签: php multithreading websocket fork

我安装了棘轮php websocket。 我在onMessage方法中使用pcntl_fork来处理新线程中的每个客户端。

public function onMessage(ConnectionInterface $from, $msg) {

    $pid = pcntl_fork();
    if ($pid == -1) {
        $this->myPrint("cant create fork");
    } else if ($pid) {

    } else {
        // ..... $result
        $from->send($result);
        // $pid = getmypid();
        // exit($pid);

    }

}

如果我尝试关闭子进程,客户端不会收到任何消息。 ($ from-> send($ result)不工作)。 如果我评论退出($ pid)。客户得到消息。

如何正确关闭子进程?

image

我试图退出:

function _exit() {
    posix_kill(posix_getpid(), SIGTERM);
}

但是,我仍有问题

0 个答案:

没有答案