/** * get value from the queue of channel * * @param bool $block if block when the queue is empty * @return bool|string */ public function get($block = false) { if ($this->block != $block) { $this->pipe->setBlock($block); $this->block = $block; } $len = $this->pipe->read(4); if ($len === false) { throw new \RuntimeException("read pipe failed"); } if (strlen($len) === 0) { return null; } $len = unpack('N', $len); if (empty($len) || !array_key_exists(1, $len) || empty($len[1])) { throw new \RuntimeException("data protocol error"); } $len = intval($len[1]); $value = ''; while (true) { $temp = $this->pipe->read($len); if (strlen($temp) == $len) { return $temp; } $value .= $temp; $len -= strlen($temp); if ($len == 0) { return $value; } } }