read() public method

This method will not wait for all the requested data, it will return as soon as any data is received.
public read ( integer $len, boolean $verifyExactLength = false ) : string
$len integer Maximum number of bytes to read.
$verifyExactLength boolean Throw an exception if the number of read bytes is less than $len
return string Binary data
Beispiel #1
0
 /**
  * Read the response error code
  *
  * @return integer Error code
  */
 protected function getResponseCode()
 {
     $this->connect();
     $data = $this->socket->read(2, true);
     $unpack = unpack('n', $data);
     return array_shift($unpack);
 }
Beispiel #2
0
 /**
  * Read the next message 
  *
  * @return string Message (raw)
  * @throws \Kafka\Exception when the message cannot be read from the stream buffer
  */
 protected function getMessage()
 {
     try {
         $size = $this->getMessageSize();
         $msg = $this->socket->read($size, true);
     } catch (Exception\Socket\EOF $e) {
         $size = isset($size) ? $size : 'enough';
         $logMsg = 'Cannot read ' . $size . ' bytes, the message is likely bigger than the buffer - original exception: ' . $e->getMessage();
         throw new Exception\OutOfRange($logMsg);
     }
     $this->validByteCount += 4 + $size;
     return $msg;
 }