StreamedResponse

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())
static StreamedResponse 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

__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

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

$this setCallback(callable $callback)

Sets the PHP callback associated with this Response.

Parameters

callable $callback A valid PHP callback

Return Value

$this

$this sendHeaders()

{@inheritdoc}

This method only sends the headers once.

Return Value

$this

$this sendContent()

{@inheritdoc}

This method only sends the content once.

Return Value

$this

$this setContent($content)

{@inheritdoc}

Parameters

$content

Return Value

$this

Exceptions

LogicException when the content is not null

false getContent()

{@inheritdoc}

Return Value

false

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/4.0/Symfony/Component/HttpFoundation/StreamedResponse.html