|
|
|
@ -114,25 +114,13 @@ class Client implements Interfaces\ClientInterface |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Read answer from server after query was executed |
|
|
|
* Read length of line |
|
|
|
* |
|
|
|
* @param bool $parse |
|
|
|
* @return array |
|
|
|
* @param int $byte |
|
|
|
* @return int |
|
|
|
*/ |
|
|
|
public function read(bool $parse = true): array |
|
|
|
private function getLength(int $byte): int |
|
|
|
{ |
|
|
|
// By default response is empty
|
|
|
|
$response = []; |
|
|
|
|
|
|
|
// Not done by default
|
|
|
|
$done = false; |
|
|
|
|
|
|
|
// Read answer from socket in loop
|
|
|
|
while (true) { |
|
|
|
// Read the first byte of input which gives us some or all of the length
|
|
|
|
// of the remaining reply.
|
|
|
|
$byte = \ord(fread($this->_socket, 1)); |
|
|
|
|
|
|
|
// If the first bit is set then we need to remove the first four bits, shift
|
|
|
|
// left 8 and then read another byte in.
|
|
|
|
//
|
|
|
|
@ -163,6 +151,29 @@ class Client implements Interfaces\ClientInterface |
|
|
|
$length = $byte; |
|
|
|
} |
|
|
|
|
|
|
|
return $length; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Read answer from server after query was executed |
|
|
|
* |
|
|
|
* @param bool $parse |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
public function read(bool $parse = true): array |
|
|
|
{ |
|
|
|
// By default response is empty
|
|
|
|
$response = []; |
|
|
|
|
|
|
|
// Read answer from socket in loop
|
|
|
|
while (true) { |
|
|
|
// Read the first byte of input which gives us some or all of the length
|
|
|
|
// of the remaining reply.
|
|
|
|
$byte = \ord(fread($this->_socket, 1)); |
|
|
|
|
|
|
|
// Read length of line
|
|
|
|
$length = $this->getLength($byte); |
|
|
|
|
|
|
|
// By default line is empty
|
|
|
|
$line = ''; |
|
|
|
|
|
|
|
@ -179,14 +190,12 @@ class Client implements Interfaces\ClientInterface |
|
|
|
} |
|
|
|
|
|
|
|
// If we get a !done, change state of done variable
|
|
|
|
if ($line === '!done') { |
|
|
|
$done = true; |
|
|
|
} |
|
|
|
$done = ($line === '!done'); |
|
|
|
|
|
|
|
// Get status about latest operation
|
|
|
|
$status = stream_get_meta_data($this->_socket); |
|
|
|
|
|
|
|
// If we do not have unread bytes from socket or <-same and is done, then exit from loop
|
|
|
|
// If we do not have unread bytes from socket or <-same and if done, then exit from loop
|
|
|
|
if ((!$status['unread_bytes']) || (!$status['unread_bytes'] && $done)) { |
|
|
|
break; |
|
|
|
} |
|
|
|
|