# ResponseBody

> Retains failures from streaming read() and eof() calls that an emitter may consume.

[API reference](/docs/api/index.md) › [RoadRunner](/docs/extensions/road-runner/reference/index.md) › ResponseBody

| final class | `yii2\extensions\roadrunner\ResponseBody` |
| --- | --- |
| Implements | `Psr\Http\Message\StreamInterface` |
| Source | [`src/ResponseBody.php`](https://github.com/yii2-extensions/road-runner/blob/main/src/ResponseBody.php#L13) |

Retains failures from streaming `read()` and `eof()` calls that an emitter may consume.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) |  | `ResponseBody` |
| [`__toString()`](#method-__toString) |  | `ResponseBody` |
| [`close()`](#method-close) |  | `ResponseBody` |
| [`detach()`](#method-detach) |  | `ResponseBody` |
| [`eof()`](#method-eof) |  | `ResponseBody` |
| [`getContents()`](#method-getContents) |  | `ResponseBody` |
| [`getFailure()`](#method-getFailure) | Returns the failure even when the emitter returned normally after consuming it. | `ResponseBody` |
| [`getMetadata()`](#method-getMetadata) |  | `ResponseBody` |
| [`getSize()`](#method-getSize) |  | `ResponseBody` |
| [`isReadable()`](#method-isReadable) |  | `ResponseBody` |
| [`isSeekable()`](#method-isSeekable) |  | `ResponseBody` |
| [`isWritable()`](#method-isWritable) |  | `ResponseBody` |
| [`read()`](#method-read) |  | `ResponseBody` |
| [`rewind()`](#method-rewind) |  | `ResponseBody` |
| [`seek()`](#method-seek) |  | `ResponseBody` |
| [`tell()`](#method-tell) |  | `ResponseBody` |
| [`write()`](#method-write) |  | `ResponseBody` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(Psr\Http\Message\StreamInterface $stream)
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$stream` | `Psr\Http\Message\StreamInterface` |  |

### __toString() <span id="method-__toString"></span>

```php
public function __toString(): string
```

**Returns**

`string`

### close() <span id="method-close"></span>

```php
public function close(): void
```

### detach() <span id="method-detach"></span>

```php
public function detach(): resource|null
```

**Returns**

`resource|null`

### eof() <span id="method-eof"></span>

```php
public function eof(): bool
```

**Returns**

`bool`

### getContents() <span id="method-getContents"></span>

```php
public function getContents(): string
```

**Returns**

`string`

### getFailure() <span id="method-getFailure"></span>

```php
public function getFailure(): Throwable|null
```

Returns the failure even when the emitter returned normally after consuming it.

**Returns**

[`Throwable`](https://www.php.net/manual/en/class.throwable.php)`|null`

### getMetadata() <span id="method-getMetadata"></span>

```php
public function getMetadata(string|null $key = null): mixed
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string\|null` |  |

**Returns**

`mixed`

### getSize() <span id="method-getSize"></span>

```php
public function getSize(): int|null
```

**Returns**

`int|null`

### isReadable() <span id="method-isReadable"></span>

```php
public function isReadable(): bool
```

**Returns**

`bool`

### isSeekable() <span id="method-isSeekable"></span>

```php
public function isSeekable(): bool
```

**Returns**

`bool`

### isWritable() <span id="method-isWritable"></span>

```php
public function isWritable(): bool
```

**Returns**

`bool`

### read() <span id="method-read"></span>

```php
public function read(int $length): string
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$length` | `int` |  |

**Returns**

`string`

### rewind() <span id="method-rewind"></span>

```php
public function rewind(): void
```

### seek() <span id="method-seek"></span>

```php
public function seek(int $offset, int $whence = \yii2\extensions\roadrunner\SEEK_SET): void
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$offset` | `int` |  |
| `$whence` | `int` |  |

### tell() <span id="method-tell"></span>

```php
public function tell(): int
```

**Returns**

`int`

### write() <span id="method-write"></span>

```php
public function write(string $string): int
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$string` | `string` |  |

**Returns**

`int`