Read data from the socket
@param integer $byte_count The amount of data to read, if not set, it reads until feof
@return string The data read from the socket
515009
public function read($byte_count=null)
    {

        $this->log('read from  socket');
        $buffer = '';

        if(!is_null($byte_count)) {
        //read the specified amount of data
            $buffer .= fgets($this->socket, 1024);
        } else {
        //read all the data
            while (!feof($this->socket)) {
                $buffer .= fgets($this->socket, 1024);
            }
        }


        return $buffer;
    }
1108430
public function decodeBytes($count = 1)
    {
        if (!is_int($count) || $count < 0) {
            throw new \InvalidArgumentException();
        }

        if (!$count) {
            return '';
        }

        return $this->buffer->get($count);
    }
144203
protected function message_read()
    {
        if ($this->socket->eof()) {
            if (++ $this->count_eof > 5) {
                usleep(pow(2, $this->count_eof));
            }

            Debug::Log(Debug::NOTICE, 'message_read(): EOF ' . $this->count_eof);

            if ($this->count_eof > $this->max_eof) {
                throw new Exception\NetworkError();
            }

            return false;
        }
        # Reset EOF counter
        $this->count_eof = 0;

        # read 2 bytes
        $read_fh_bytes = 2;
        $read_more_length_bytes = 3;

        $read_bytes = 0;
        $read_message = $this->socket->read($read_fh_bytes);
        if (empty($read_message)) {
            throw new Exception('WTFFFFFF!!!! ');
        }
        $read_bytes += $read_fh_bytes;

        $cmd = Utility::ParseCommand(ord($read_message[0]));

        $message_type = $cmd['message_type'];
        $flags        = $cmd['flags'];

        Debug::Log(Debug::DEBUG, "message_read(): message_type=".Message::$name[$message_type].", flags={$flags}");

        if (ord($read_message[1]) > 0x7f) {
            # read 3 more bytes
            $read_message .= $this->socket->read($read_more_length_bytes);
            $read_bytes += $read_more_length_bytes;
        }

        $pos = 1;
        $remaining_length = Utility::DecodeLength($read_message, $pos);

        $to_read = 0;
        if ($remaining_length) {
            $to_read = $remaining_length - ($read_bytes - $pos);
        }

        Debug::Log(Debug::DEBUG, 'message_read(): remaining length=' . $remaining_length . ', data to read='.$to_read);
        if ($to_read) {
            $read_message .= $this->socket->read($to_read);
        }

        Debug::Log(Debug::DEBUG, 'message_read(): Dump', $read_message);

        $message_object = $this->getMessageObject($message_type);
        $message_object->decode($read_message, $remaining_length);

        return $message_object;
    }
1159708
public function read($count_bytes) {
    // If we have data in the read_buffer then use it.
    $readBuffer_size = strlen($this->read_buffer);
    $bytes_available = $readBuffer_size - $this->buffer_read_position;

    // If there are no more bytes available then get some.
    if ($bytes_available === 0 && !$this->eof) {
      // If we know the object size, check it first.
      $object_bytes_read = $this->object_block_start_position +
                           $this->buffer_read_position;
      if ($object_bytes_read === $this->object_total_length ||
          !isset($this->next_read_position)) {
        $this->eof = true;
        return false;
      }
      if (!$this->fillReadBuffer($this->next_read_position)) {
        return false;
      }
      // Re-calculate the number of bytes we can serve.
      $readBuffer_size = strlen($this->read_buffer);
      $bytes_available = $readBuffer_size - $this->buffer_read_position;
    }

    if ($bytes_available > 0) {
      $bytes_to_read = min($bytes_available, $count_bytes);
      $current_buffer_position = $this->buffer_read_position;
      $this->buffer_read_position += $bytes_to_read;

      return substr($this->read_buffer,
                    $current_buffer_position,
                    $bytes_to_read);
    }

    return false;
  }
263265
private function readChunked(): string
    {
        $readLength = 0;
        $chunksize  = null;
        $extension  = null;
        $body       = '';
        sscanf($this->socket->readLine(), '%x%s', $chunksize, $extension);
        while (0 < $chunksize) {
            $data        = $this->socket->read($chunksize + 4);
            $body       .= rtrim($data);
            $readLength += $chunksize;
            sscanf($this->socket->readLine(), '%x', $chunksize);
        }

        $this->headers->put('Content-Length', $readLength);
        $this->headers->remove('Transfer-Encoding');
        return $body;
    }
656865
public function readFile(string $file_name)
    {
        $contents = @file_get_contents($file_name);
        if ($contents === false)
            throw new IOException("Failed to read file contents");

        $contents = Encoding::removeBOM($contents);
        return $this->readString(file_get_contents($file_name));
    }
717395
public function read($bytesRequested)
    {
        if($this->_currentPart >= count($this->_parts)) {
          return FALSE;
        }

        $activePart = $this->_parts[$this->_currentPart];
        $buffer = $activePart->read($bytesRequested);

        while(strlen($buffer) < $bytesRequested) {
          $this->_currentPart += 1;
          $nextBuffer = $this->read($bytesRequested - strlen($buffer));
          if($nextBuffer === FALSE) {
            break;
          }
          $buffer .= $nextBuffer;
        }

        return $buffer;
    }
460294
public function readBytes(int $bytes): string
	{
		if ($this->connected() === false)
		{
			throw new \Exception('Not connected');
		}

		$response = fread($this->connection, $bytes);

		if ($response === false)
		{
			throw new \Exception('Nothing to read');
		}

		return $response;
	}
39305
public function read($bytes = 2082)
    {
        return feof($this->stream) ? false : fread($this->stream, $bytes);
    }
930267
public function read($size)
    {
        $this->_checkStream();
        $data = @fread($this->_stream, $size);
        if ($data === false) {
            throw new Client\Exception('Error reading data from socket');
        }
        return $data;
    }
932871
public function stream_read($count)
    {
        if (!$this->_objectName) {
            return '';
        }

        // make sure that count doesn't exceed object size
        if ($count + $this->_position > $this->_objectSize) {
            $count = $this->_objectSize - $this->_position;
        }

        $range_start = $this->_position;
        $range_end = $this->_position + $count -1;

        // Only fetch more data from OSS if we haven't fetched any data yet (postion=0)
        // OR, the range end position is greater than the size of the current object
        // buffer AND if the range end position is less than or equal to the object's
        // size returned by OSS
        if (($this->_position == 0) || (($range_end > strlen($this->_objectBuffer)) && ($range_end <= $this->_objectSize))) {
            $options = [
                OssClient::OSS_RANGE => $range_start.'-'.$range_end,
            ];
            $this->_objectBuffer .= $this->_oss->getObject(AliyunOSS::getBucket(), $this->_objectName, $options);
        }

        $data = substr($this->_objectBuffer, $this->_position, $count);
        $this->_position += strlen($data);

        return $data;
    }
1177770
public function getRandomBytes($count)
    {
        $count = (int) $count;
        $bytes = '';
        $hasBytes = false;

		if (version_compare(PHP_VERSION, '7.0.0') >= 0 && function_exists('random_bytes'))
        {
            try
            {
                $bytes = \random_bytes($count);
                $hasBytes = true;
            }
            catch (\Exception $e)
            {
                //
            }
        }
        
        // Make sure PHP version is at least 5.3. We do this because
        // mcrypt_create_iv() on older versions of PHP
        // does not give "strong" random data on Windows systems.
        if (version_compare(PHP_VERSION, '5.3.0') >= 0 && function_exists('mcrypt_create_iv'))
        {
        	// Suppress deprecation warning in PHP 7.1
            $tmp = @mcrypt_create_iv($count, MCRYPT_DEV_URANDOM);
            if ($tmp !== false)
            {
                $bytes = $tmp;
                $hasBytes = true;
            }
        }

        if ($hasBytes === false && file_exists('/dev/urandom') && is_readable('/dev/urandom') && (false !== ($fh = fopen('/dev/urandom', 'rb'))))
        {
            if (function_exists('stream_set_read_buffer'))
            {
                stream_set_read_buffer($fh, 0);
            }

            $tmp = fread($fh, $count);
            fclose($fh);
            if ($tmp !== false)
            {
                $bytes = $tmp;
                $hasBytes = true;
            }
        }

        /*
         * We want to play it safe and disable openssl_random_pseudo_bytes() for now.
         * This is due to the OpenSSL "PID wrapping bug", which potentially could affect GenPhrase.
         *
        if ($hasBytes === false && version_compare(PHP_VERSION, '5.3.4') >= 0 && function_exists('openssl_random_pseudo_bytes'))
        {
            $tmp = openssl_random_pseudo_bytes($count, $cryptoStrong);
            if ($tmp !== false && $cryptoStrong === true)
            {
                $bytes = $tmp;
                $hasBytes = true;
            }
        }
        */

        if (isset($bytes[$count - 1]) && !isset($bytes[$count]))
        {
            return $bytes;
        }
        else
        {
            return false;
        }
    }
354776
function read($inByte = null)
    {
        if ($this->getSegmentLimit() == -1)
            return $this->_t__wrap_stream->read($inByte);


        $inByte = ($inByte === null)
            ? (
                ($this->getBuffer() === null) ? $this->getSize() : $this->getBuffer()

            ) : $inByte;

        $remain = $this->getSegmentLimit() - $this->getCurrOffset();
        if ($remain > 0)
            return $this->_t__wrap_stream->read(min($remain, $inByte));

        return '';
    }
1328416
public function readVInt()
    {
        $nextByte = ord($this->_fread(1));
        $val = $nextByte & 0x7F;

        for ($shift=7; ($nextByte & 0x80) != 0; $shift += 7) {
            $nextByte = ord($this->_fread(1));
            $val |= ($nextByte & 0x7F) << $shift;
        }
        return $val;
    }
1135370
def readinto(self, byte_array):
        
        max_size = len(byte_array)
        data = self.read(max_size)
        bytes_read = len(data)
        byte_array[:bytes_read] = data
        return bytes_read
94373
public function read()
        {
            // Ignore first byte, I hope Socket.io does not send fragmented frames, so we don't have to deal with FIN bit.
            // There are also reserved bit's which are 0 in socket.io, and opcode, which is always "text frame" in Socket.io
            fread($this->fd, 1);

            // There is also masking bit, as MSB, but it's 0 in current Socket.io
            $payload_len = ord(fread($this->fd, 1));

            switch ($payload_len) {
                case 126:
                    $payload_len = unpack("n", fread($this->fd, 2));
                    $payload_len = $payload_len[1];
                    break;
                case 127:
                    $this->stdout('error', "Next 8 bytes are 64bit uint payload length, not yet implemented, since PHP can't handle 64bit longs!");
                    break;
            }

            // Use buffering to handle packet size > 16Kb
            $read       = 0;
            $payload    = '';

            while ($read < $payload_len && ($buff = fread($this->fd, $payload_len - $read))) {
                $read += strlen($buff);
                $payload .= $buff;
            }

            $this->stdout('debug', 'Received ' . $payload);

            return $payload;
        }
1033387
public void readBytes (Object to, long offset, int count) throws KryoException {
		int copyCount = Math.min(limit - position, count);
		while (true) {
			unsafe.copyMemory(null, bufferAddress + position, to, offset, copyCount);
			position += copyCount;
			count -= copyCount;
			if (count == 0) break;
			offset += copyCount;
			copyCount = Math.min(count, capacity);
			require(copyCount);
		}
		byteBuffer.position(position);
	}