在select的构造函数中,有如下代码
// Create a pipeline and put into the collection of the read to read the descriptor to avoid empty polling.
$this->channel = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
if ($this->channel) {
stream_set_blocking($this->channel, 0);
$this->_readFds = $this->channel;
}
?>
这个创造出来的一对套接字,一般是被用来进行进程间通信的,但是一般的使用方式是这样
$sockets = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
/_ parent _/
fclose($sockets);
fwrite($sockets, "child PID: $pid\n");
echo fgets($sockets);
fclose($sockets);
} else {
/_ child _/
fclose($sockets);
fwrite($sockets, "message from child\n");
echo fgets($sockets);
fclose($sockets);
}
?>
使用一对套接字,在进程分裂的时候每个进程拥有其副本,然后互相发送,可以得到消息
但是workerman中的stream_socket_pair的创建是在子进程分裂之后,的run中,才给每一个子进程创建一对stream_socket_pair,而且只在_readFds中加入了channel的第一个,另外一个不知道用到哪儿了,请问walkor老大,这样做是什么目的啊,每看明白