Skip to content

Commit d4ce68e

Browse files
committed
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>
1 parent 4775ce4 commit d4ce68e

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

lib/private/AppFramework/App.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,10 @@ public static function main(
213213
$io->setOutput($output);
214214
}
215215
}
216+
217+
if ($response->getFlushEarly()) {
218+
ob_flush();
219+
flush();
220+
}
216221
}
217222
}

lib/public/AppFramework/Http/Response.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Response {
6666

6767
/** @var bool */
6868
private $throttled = false;
69+
private bool $flushEarly = true;
6970
/** @var array */
7071
private $throttleMetadata = [];
7172

@@ -412,4 +413,25 @@ public function getThrottleMetadata() {
412413
public function isThrottled() {
413414
return $this->throttled;
414415
}
416+
417+
/**
418+
* Request the response should be flushed to the connected client immediately
419+
*
420+
* @since 34.0.0
421+
*/
422+
public function setFlushEarly(bool $flushEarly): void {
423+
$this->flushEarly = $flushEarly;
424+
}
425+
426+
/**
427+
* Whether the response should be flushed to the connected client immediately
428+
*
429+
* If not, the response will wait for async actions, e.g. HTTP requests from
430+
* IClientService, to be finished before returning.
431+
*
432+
* @since 34.0.0
433+
*/
434+
public function getFlushEarly(): bool {
435+
return $this->flushEarly;
436+
}
415437
}

0 commit comments

Comments
 (0)