Livestatus\Connection: implement readLineFromSocket

We want to stream data in the near future, so reading line by line is
essential
This commit is contained in:
Thomas Gelf 2014-11-16 15:55:53 +01:00
parent a027efc9e7
commit 8ec8c153dd
1 changed files with 22 additions and 0 deletions

View File

@ -248,6 +248,28 @@ class Connection
return $buffer;
}
protected function readLineFromSocket()
{
if ($this->bytesRead === $this->responseSize) {
return false;
}
$maxRowLength = 100 * 1024;
$row = socket_read($this->getConnection(), $maxRowLength, PHP_NORMAL_READ);
$this->bytesRead += strlen($row);
if ($row === false) {
$this->socketError('Failed to read next row from livestatus socket');
}
return $row;
}
/**
* Write given string to livestatus socket
*
* @param string $data Data string to write to the socket
*
* @return boolean
*/
protected function writeToSocket($data)
{
$res = @socket_write($this->getConnection(), $data);