Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HttpFoundation] Add StreamedResponse string iterable #20466

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions components/http_foundation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,19 @@ Streaming a Response
~~~~~~~~~~~~~~~~~~~~

The :class:`Symfony\\Component\\HttpFoundation\\StreamedResponse` class allows
you to stream the Response back to the client. The response content is
represented by a PHP callable instead of a string::
you to stream the Response back to the client. The response content can be
represented by a string iterable::

use Symfony\Component\HttpFoundation\StreamedResponse;

$chunks = ['Hello', ' World'];

$response = new StreamedResponse();
$response->setChunks($chunks);
$response->send();

mtarld marked this conversation as resolved.
Show resolved Hide resolved
For most complex use cases, the response content can be instead represented by
a PHP callable::

use Symfony\Component\HttpFoundation\StreamedResponse;

Expand Down Expand Up @@ -710,6 +721,10 @@ represented by a PHP callable instead of a string::
// disables FastCGI buffering in nginx only for this response
$response->headers->set('X-Accel-Buffering', 'no');

.. versionadded:: 7.3

Support for using string iterables was introduced in Symfony 7.3.

Streaming a JSON Response
~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
Loading