php - WebSocket, pcntl_fork, close child process correctly

天大地大妈咪最大 提交于 2019-12-11 03:52:32

问题


I install ratchet php websocket. I do pcntl_fork in onMessage method to work with every client in new thread.

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);

    }

}

if i try to close child process, client dont get any message. ($from->send($result) dont work). if i comment exit($pid) . Client get message.

How to close child process correctly ?

i tried to do exit with:

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

but, I still have a problem

来源:https://stackoverflow.com/questions/27343348/php-websocket-pcntl-fork-close-child-process-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!