Reads the result from socket and parses it
@return array|bool|null|string
@throws CException socket or data problems
10844
private function parseResponse()
	{
		if(($line=fgets($this->_socket))===false)
			throw new CException('Failed reading data from redis connection socket.');
		$type=$line[0];
		$line=substr($line,1,-2);
		switch($type)
		{
			case '+': // Status reply
				return true;
			case '-': // Error reply
				throw new CException('Redis error: '.$line);
			case ':': // Integer reply
				// no cast to int as it is in the range of a signed 64 bit integer
				return $line;
			case '$': // Bulk replies
				if($line=='-1')
					return null;
				$length=$line+2;
				$data='';
				while($length>0)
				{
					if(($block=fread($this->_socket,$length))===false)
						throw new CException('Failed reading data from redis connection socket.');
					$data.=$block;
					$length-=$this->byteLength($block);
				}
				return substr($data,0,-2);
			case '*': // Multi-bulk replies
				$count=(int)$line;
				$data=array();
				for($i=0;$i<$count;$i++)
					$data[]=$this->parseResponse();
				return $data;
			default:
				throw new CException('Unable to parse data received from redis.');
		}
	}
905390
public function parse()
    {
        $result = new stdClass();
        $cache = $parser = $exception = $cacheKey = $path = null;
        try {
            $path = $this->find(false);
            // Cached response
            $cache = new PathCache(__FUNCTION__, $this->options);
            $cacheKey = $cache->getKey([$path]);
            $result = $cache->readFrom($cacheKey);
            if ($result !== false) {
                return $result;
            }
            // Real response
            $parser = $this->getParser();
            $result = $parser->parse($path);
        } catch (InvalidArgumentException $exception) {
            $this->mergeMessages($exception, __FUNCTION__);
        }
        $this->mergeMessages($parser, __FUNCTION__);
        $this->mergeMessages($cache, __FUNCTION__);

        // Re-throw parser exception
        if ($exception) {
            throw $exception;
        }

        if ($cache && $cacheKey) {
            $cache->writeTo($cacheKey, $result, ['path' => $path]);
        }

        return $result;
    }
660833
public function parse()
    {
        if ($this->buffer === '') {
            return false;
        }
        $this->frame = null;
        $this->offset = 0;
        $this->bufferSize = strlen($this->buffer);
        while ($this->offset < $this->bufferSize) {
            if ($this->mode === self::MODE_HEADER) {
                $this->skipEmptyLines();
                if ($this->detectFrameHead()) {
                    $this->mode = self::MODE_BODY;
                } else {
                    break;
                }
            }
            if ($this->detectFrameEnd()) {
                $this->mode = self::MODE_HEADER;
            }
            break;
        }

        if ($this->offset > 0) {
            // remove parsed buffer
            $this->buffer = substr($this->buffer, $this->offset);
        }
        return $this->frame !== null;
    }
1366849
protected function _peekRead()
    {
        $status = strtok($this->_read(), ' ');

        switch ($status) {
            case 'FOUND':
                return [
                    'id' => (integer) strtok(' '),
                    'body' => $this->_read((integer) strtok(' ')),
                ];
            case 'NOT_FOUND':
                return false;
            default:
                throw new ServerException('Peek error: '.$status);
        }
    }
1322178
private function receive()
    {
        $timer = microtime(true);

        $str = fgets($this->socket);

        if ($str === false) {
            $this->close();
            throw new HSException('Cannot read from socket');
        }


        $this->logs[] = [
            'type' => 'receive',
            'time' => microtime(true) - $timer,
            'command' => $str
        ];

        return substr($str, 0, -1);
    }
98298
private function parseByteArray()
    {
        list(, $length) = unpack('N', $this->buffer);

        try {
            return substr($this->buffer, 4, $length);
        } finally {
            $this->buffer = substr($this->buffer, $length + 4);
        }
    }
354111
function recv()
    {
        if (!$this->handshake)
        {
            trigger_error("not complete handshake.");
            return false;
        }
        if ($this->buffer and  $offset = stripos($this->buffer,"\r\n\r\n") !== false)
        {
            $packet = substr($this->buffer, 0, $offset + 4);
            $next = substr($this->buffer, $offset + 4);
            if ($next) {
                $this->buffer = $next;
            }
            $this->parser->push($packet);
            $frame = $this->parser->pop();
            if ($frame)
            {
                return $frame->data;
            }
        } else {
            while (true)
            {
                $data = $this->socket->recv();
                if ($this->buffer) {
                    $data = $this->buffer.$data;
                    $this->buffer = '';
                }
                if (!$data)
                {
                    return false;
                }
                $this->parser->push($data);
                $frame = $this->parser->pop();
                if ($frame)
                {
                    return $frame->data;
                }
            }
        }
        return false;
    }
726959
public function parse()
    {
        $count = (int) $this->data;
        if ($count < 0) {
            return null;
        }

        $elements = [];
        for ($i=0; $i < $count; $i++) {
            $elements[$i] = call_user_func($this->receiver);
        }
        return $elements;
    }
1301827
public function read(): array
    {
        while (!$this->streamBody->eof()) {
            $tweet = json_decode(
                $this->readStreamLine($this->streamBody),
                true
            );

            if (null !== $tweet) {
                return $tweet;
            }
        }
    }
737772
protected function read(): string
    {
        $s = '';
        while (($line = \fgets($this->connection, 1000)) != null) { // intentionally ==
            $s .= $line;
            if (isset($line[3]) && $line[3] === ' ') {
                break;
            }
        }

        return $s;
    }
1086752
public function read()
	{
		$this->position++;
		if ( $this->position >= count( $this->buffer ) ) return false;

		return $this->buffer[ $this->position ];
	}
203798
public function readByte()
    {
        if (!is_resource($this->fp)) {
            return $this->raiseError('not connected');
        }

        return ord(@fread($this->fp, 1));
    }
1314094
public function read(): array
    {
        if ( isset($this->data)) {
            return $this->data;
        }

        $this->data = [];
        foreach ($this->source as &$row) {
            //checking if the source corresponds to the wanted format
            if (array_filter($row, 'is_scalar') == $row) {
                $this->data[] = $row;
            }
        }

        return $this->data;
    }
473003
protected function read($socket)
    {
        $result = fgets($socket);
        if ($result === false) {
            throw new \RuntimeException();
        }
        return $this->unserialize($result);
    }
517909
protected function onRead()
    {
        start:
        if ($this->state === self::STATE_ROOT) {
            while (($l = $this->readLine()) !== null) {
                $e = explode(' ', $l);

                if ($e[0] === 'VALUE') {
                    $this->key = $e[1];
                    $this->valueFlags = $e[2];
                    $this->valueLength = $e[3];
                    $this->result = '';
                    $this->setWatermark($this->valueLength);
                    $this->state = self::STATE_DATA;
                    break;
                } elseif ($e[0] === 'STAT') {
                    if ($this->result === null) {
                        $this->result = [];
                    }

                    $this->result[$e[1]] = $e[2];
                } elseif (($e[0] === 'STORED') || ($e[0] === 'END') || ($e[0] === 'DELETED') || ($e[0] === 'ERROR')
                    || ($e[0] === 'CLIENT_ERROR') || ($e[0] === 'SERVER_ERROR')
                ) {
                    if ($e[0] !== 'END') {
                        $this->result = false;
                        $this->error = isset($e[1]) ? $e[1] : null;
                    }
                    $this->onResponse->executeOne($this);
                    $this->checkFree();
                    $this->result = null;
                }
            }
        }

        if ($this->state === self::STATE_DATA) {
            if (false === ($this->result = $this->readExact($this->valueLength))) {
                return; //we do not have a whole packet
            }
            $this->state = self::STATE_ROOT;
            $this->setWatermark(1);
            goto start;
        }
    }
446372
public function peek()
	{
		if($this->_c)
			return $this->_d[$this->_c-1];
		else
			throw new CException(Yii::t('yii','The stack is empty.'));
	}
1317165
public function parse()
    {
        $bytes = (int) $this->data;
        if ($bytes < 0) {
            return null;
        }

        $bytes += 2; // CRLF
        $string = '';

        do {
            $buffer = $this->read($bytes);
            $string .= $buffer;
            $bytes -= strlen($buffer);
        } while ($bytes > 0);

        return substr($string, 0, -2); // Remove last CRLF
    }