问题
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