Skip to content

Commit 923ecdb

Browse files
feature symfony#52047 [HttpFoundation][Runtime] Add $flush parameter to Response::send() (fancyweb)
This PR was merged into the 6.4 branch. Discussion ---------- [HttpFoundation][Runtime] Add $flush parameter to Response::send() | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT Inspired by symfony#51912 and symfony#45205 subjects Adds optional argument `$flush` to `Response::send()`. If `$flush === false`, output buffers are not flushed/`*_finish_request()` and alike functions are not called. We leverage that in the Runtime component by not flushing the output buffers when debug mode is on in order to see exceptions thrown in listeners listening on the `TerminateEvent` and also to feel a more "real" processing time of things happening on terminate. Commits ------- a3304cc [HttpFoundation] Add $flush parameter to Response::send()
2 parents e4c4856 + a3304cc commit 923ecdb

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

src/Symfony/Component/HttpFoundation/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* Support root-level `Generator` in `StreamedJsonResponse`
99
* Add `UriSigner` from the HttpKernel component
1010
* Add `partitioned` flag to `Cookie` (CHIPS Cookie)
11+
* Add argument `bool $flush = true` to `Response::send()`
1112

1213
6.3
1314
---

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,20 @@ public function sendContent(): static
415415
/**
416416
* Sends HTTP headers and content.
417417
*
418+
* @param bool $flush Whether output buffers should be flushed
419+
*
418420
* @return $this
419421
*/
420-
public function send(): static
422+
public function send(/* bool $flush = true */): static
421423
{
422424
$this->sendHeaders();
423425
$this->sendContent();
424426

427+
$flush = 1 <= \func_num_args() ? func_get_arg(0) : true;
428+
if (!$flush) {
429+
return $this;
430+
}
431+
425432
if (\function_exists('fastcgi_finish_request')) {
426433
fastcgi_finish_request();
427434
} elseif (\function_exists('litespeed_finish_request')) {

src/Symfony/Component/Runtime/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.4
5+
---
6+
7+
* Add argument `bool $debug = false` to `HttpKernelRunner::__construct()`
8+
49
5.4
510
---
611

src/Symfony/Component/Runtime/Runner/Symfony/HttpKernelRunner.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ class HttpKernelRunner implements RunnerInterface
2424
public function __construct(
2525
private readonly HttpKernelInterface $kernel,
2626
private readonly Request $request,
27+
private readonly bool $debug = false,
2728
) {
2829
}
2930

3031
public function run(): int
3132
{
3233
$response = $this->kernel->handle($this->request);
33-
$response->send();
34+
$response->send(!$this->debug);
3435

3536
if ($this->kernel instanceof TerminableInterface) {
3637
$this->kernel->terminate($this->request, $response);

src/Symfony/Component/Runtime/SymfonyRuntime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function __construct(array $options = [])
131131
public function getRunner(?object $application): RunnerInterface
132132
{
133133
if ($application instanceof HttpKernelInterface) {
134-
return new HttpKernelRunner($application, Request::createFromGlobals());
134+
return new HttpKernelRunner($application, Request::createFromGlobals(), $this->options['debug'] ?? false);
135135
}
136136

137137
if ($application instanceof Response) {

0 commit comments

Comments
 (0)