From d4ce68e0f967c9a7758254efbf168798decbbbe9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 2 Feb 2026 11:43:39 +0100 Subject: [PATCH] perf(response): Flush requests early to clients If not, the response will wait for async actions, e.g. HTTP requests from IClientService, to be finished before returning. This is not desired in many cases with e.g. with notifications. Signed-off-by: Joas Schilling --- lib/private/AppFramework/App.php | 5 +++++ lib/public/AppFramework/Http/Response.php | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/private/AppFramework/App.php b/lib/private/AppFramework/App.php index 7bf328522094b..1a82fe583451e 100644 --- a/lib/private/AppFramework/App.php +++ b/lib/private/AppFramework/App.php @@ -213,5 +213,10 @@ public static function main( $io->setOutput($output); } } + + if ($response->getFlushEarly()) { + ob_flush(); + flush(); + } } } diff --git a/lib/public/AppFramework/Http/Response.php b/lib/public/AppFramework/Http/Response.php index 6edd32a1f8b69..b602776567b13 100644 --- a/lib/public/AppFramework/Http/Response.php +++ b/lib/public/AppFramework/Http/Response.php @@ -66,6 +66,7 @@ class Response { /** @var bool */ private $throttled = false; + private bool $flushEarly = true; /** @var array */ private $throttleMetadata = []; @@ -412,4 +413,25 @@ public function getThrottleMetadata() { public function isThrottled() { return $this->throttled; } + + /** + * Request the response should be flushed to the connected client immediately + * + * @since 34.0.0 + */ + public function setFlushEarly(bool $flushEarly): void { + $this->flushEarly = $flushEarly; + } + + /** + * Whether the response should be flushed to the connected client immediately + * + * If not, the response will wait for async actions, e.g. HTTP requests from + * IClientService, to be finished before returning. + * + * @since 34.0.0 + */ + public function getFlushEarly(): bool { + return $this->flushEarly; + } }