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 <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2026-02-02 11:43:39 +01:00
parent 4775ce4266
commit d4ce68e0f9
No known key found for this signature in database
GPG key ID: F72FA5B49FFA96B0
2 changed files with 27 additions and 0 deletions

View file

@ -213,5 +213,10 @@ class App {
$io->setOutput($output);
}
}
if ($response->getFlushEarly()) {
ob_flush();
flush();
}
}
}

View file

@ -66,6 +66,7 @@ class Response {
/** @var bool */
private $throttled = false;
private bool $flushEarly = true;
/** @var array */
private $throttleMetadata = [];
@ -412,4 +413,25 @@ class Response {
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;
}
}