class StreamedResponse extends Response

StreamedResponse represents a streamed HTTP response.

A StreamedResponse uses a callback for its content.

The callback should use the standard PHP functions like echo to stream the response back to the client. The flush() method can also be used if needed.

Methods

__construct(callable $callback = null, int $status = 200, array $headers = array())

No description

create(callable|null $callback = null, int $status = 200, array $headers = array())

Factory method for chainability.

$this
setCallback(callable $callback)

Sets the PHP callback associated with this Response.

$this
sendHeaders()

{@inheritdoc}

$this
sendContent()

{@inheritdoc}

$this
setContent($content)

{@inheritdoc}

false
getContent()

{@inheritdoc}

Details

at line line 38
__construct(callable $callback = null, int $status = 200, array $headers = array())

Parameters

callable $callback A valid PHP callback or null to set it later
int $status The response status code
array $headers An array of response headers

at line line 58
static StreamedResponse create(callable|null $callback = null, int $status = 200, array $headers = array())

Factory method for chainability.

Parameters

callable|null $callback A valid PHP callback or null to set it later
int $status The response status code
array $headers An array of response headers

Return Value

StreamedResponse

at line line 70
$this setCallback(callable $callback)

Sets the PHP callback associated with this Response.

Parameters

callable $callback A valid PHP callback

Return Value

$this

at line line 84
$this sendHeaders()

{@inheritdoc}

This method only sends the headers once.

Return Value

$this

at line line 102
$this sendContent()

{@inheritdoc}

This method only sends the content once.

Return Value

$this

at line line 126
$this setContent($content)

{@inheritdoc}

Parameters

$content

Return Value

$this

Exceptions

LogicException when the content is not null

at line line 140
false getContent()

{@inheritdoc}

Return Value

false