stream = $stream; $this->isOpen(); } public function send($data) { fwrite($this->stream, json_encode($data)."\0"); } public function receive() { $buf = fread($this->stream, 8192); return json_decode(rtrim($buf, "\0")); } public function isOpen(): bool { return is_resource($this->stream); } public static function createPair() { $fd = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); return [ new StreamChannel($fd[0]), new StreamChannel($fd[1]) ]; } }