非阻塞循环读取，不能用于阻塞socket
@param $fp
@param $length
@return string
16619
static function read($fp,$length)
    {
        $data = '';
        while($buf = fread($fp, $length))
        {
            $data .= $buf;
            if(strlen($buf) < $length) break;
        }
        return $data;
    }
5724
protected function _read($length = null) {
		if (!$this->connected) {
			$message = 'No connection found while reading data from socket.';
			throw new RuntimeException($message);
		}
		if ($length) {
			if (feof($this->_connection)) {
				return false;
			}
			$data = stream_get_contents($this->_connection, $length + 2);
			$meta = stream_get_meta_data($this->_connection);

			if ($meta['timed_out']) {
				$message = 'Connection timed out while reading data from socket.';
				throw new RuntimeException($message);
			}
			$packet = rtrim($data, "\r\n");
		} else {
			$packet = stream_get_line($this->_connection, 16384, "\r\n");
		}
		return $packet;
	}
1033400
public function read(int $length = 8192): string
    {
        return iconv($this->charset, 'UTF-8', $this->inputStream->read($length));
    }
1003324
public function readLine($length = null) {
        $this->openRead();
        if (empty($length)) {
            return fgets($this->stream);
        }
        return fgets($this->stream, $length);
    }
119774
public function read(int $length = 8192): string
    {
        $bytes           = substr($this->buffer, $this->position, $length);
        $this->position += strlen($bytes);
        return $bytes;
    }
935379
public function read(int $length = 8192): string
    {
        $isAcceptable = $this->predicate;
        while (!$this->inputStream->eof()) {
            $data = $this->inputStream->read($length);
            if ($isAcceptable($data)) {
                return $data;
            }
        }

        return '';
    }
940471
public function Read( $Length = 1400 )
		{
			$Buffer = new Buffer( );
			$Buffer->Set( FRead( $this->Socket, $Length ) );
			
			$this->ReadInternal( $Buffer, $Length, [ $this, 'Sherlock' ] );
			
			return $Buffer;
		}
979454
public function readBinary(int $length = 1024): string
    {
        $data = fread($this->resource, $length);
        if (false === $data) {
            if (stream_get_meta_data($this->resource)['timed_out']) {
                throw new Timeout(
                        'Reading of ' . $length . ' bytes failed: timeout of '
                        . $this->timeout . ' seconds exceeded'
                );
            }

            throw new ConnectionFailure(
                    'Reading of ' . $length . ' bytes failed.'
            );
        }

        return $data;
    }
492971
protected function _fread($length = 1)
    {
        $returnValue = substr($this->_data, $this->_position, $length);
        $this->_position += $length;
        return $returnValue;
    }
116694
public function read($length = 4096)
  {
    $this->connect();
    $this->waitForReadyRead();

    $data = @stream_get_contents($this->stream, $length);

    Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data);

    if($data === FALSE)
    {
      throw new Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost");
    }

    return new Str($data);
  }
78672
public function getReadBuffer(&$length): Promise
    {
        $size = fstat($this->memory_stream)['size'];
        $offset = ftell($this->memory_stream);
        $length = $size - $offset;
        if ($length === 0 || $size > self::MAX_SIZE) {
            $new_memory_stream = fopen('php://memory', 'r+');
            if ($length) {
                fwrite($new_memory_stream, fread($this->memory_stream, $length));
                fseek($new_memory_stream, 0);
            }
            fclose($this->memory_stream);
            $this->memory_stream = $new_memory_stream;
        }

        return new \Amp\Success($this);
    }
717713
public function read($length)
    {
        if ($length < 1) {
            return '';
        }

        $buffer = fread($this->stream, $length);

        if ($buffer === false) {
            throw new RuntimeException('Failed to read ' . $length . ' bytes');
        }

        return $buffer;
    }
281346
function _connect(&$fp)
	{
		if(!empty($this->proxy_host) && !empty($this->proxy_port))
		{
			$this->_isproxy = true;

			$host = $this->proxy_host;
			$port = $this->proxy_port;
		}
		else
		{
			$host = $this->host;
			$port = $this->port;
		}

		$this->status = 0;

		if($fp = fsockopen(
				$host,
				$port,
				$errno,
				$errstr,
				$this->_fp_timeout
		))
		{
			// socket connection succeeded

			return true;
		}
		else
		{
			// socket connection failed
			$this->status = $errno;
			switch($errno)
			{
				case -3:
					$this->error="socket creation failed (-3)";
				case -4:
					$this->error="dns lookup failure (-4)";
				case -5:
					$this->error="connection refused or timed out (-5)";
				default:
					$this->error="connection failed (".$errno.")";
			}
			return false;
		}
	}
1189491
final protected function fgets($length = null)
	{
		if (! is_int($length)) {
			$length = $this->fstat('size');
		}
		return fgets($this->fhandle, $length);
	}
795786
public function stream_read($length)
    {
        $data = substr($this->_data, $this->_position, $length);
        $this->_position += strlen($data);

        return $data;
    }
480466
public function fwrite(string $str, int $length = null)
    {
        $args = [$this->stream, $str];
        if (null !== $length) {
            $args[] = $length;
        }

        return fwrite(...$args);
    }
23643
function send($data, $length = null) {
        if (!isset($this->pipes[0]))
            return 0;
        if (!isset($length))
            $length = strlen($data);
        return intval(fwrite($this->pipes[0], $data, $length));
    }