lithium\net\socket\Stream::read PHP Method

read() public method

Reads data from the stream resource
public read ( integer $length = null, integer $offset = null ) : string
$length integer If specified, will read up to $length bytes from the stream. If no value is specified, all remaining bytes in the buffer will be read.
$offset integer Seek to the specified byte offset before reading.
return string Returns string read from stream resource on success, false otherwise.
    public function read($length = null, $offset = null)
    {
        if (!is_resource($this->_resource)) {
            return false;
        }
        if (!$length) {
            return stream_get_contents($this->_resource);
        }
        return stream_get_contents($this->_resource, $length, $offset);
    }

Usage Example

Example #1
0
 public function testWriteAndRead()
 {
     $stream = new Stream($this->_testConfig);
     $this->assertTrue(is_resource($stream->open()));
     $this->assertTrue(is_resource($stream->resource()));
     $result = $stream->write();
     $this->assertEqual(83, $result);
     $this->assertPattern("/^HTTP/", (string) $stream->read());
 }
All Usage Examples Of lithium\net\socket\Stream::read