From 5210e314024160fef252cd0bde51baa6d672ba79 Mon Sep 17 00:00:00 2001 From: Ben Croker Date: Thu, 31 Oct 2024 22:14:32 +0100 Subject: [PATCH] Better code comments --- src/controllers/ResponseController.php | 4 +++- src/services/ResponseService.php | 11 +++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/controllers/ResponseController.php b/src/controllers/ResponseController.php index 1663385..21ff359 100644 --- a/src/controllers/ResponseController.php +++ b/src/controllers/ResponseController.php @@ -36,11 +36,13 @@ public function actionIndex(): Response $this->response->getHeaders()->set('Cache-Control', 'no-cache'); $this->response->getHeaders()->set('Connection', 'keep-alive'); - // Disable buffering for Nginx + // Disable buffering for Nginx. // https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering $this->response->getHeaders()->set('X-Accel-Buffering', 'no'); $this->response->format = Response::FORMAT_RAW; + + // Stream the response. $this->response->stream = function() use ($config, $store) { return Spark::$plugin->response->stream($config, $store); }; diff --git a/src/services/ResponseService.php b/src/services/ResponseService.php index 59d9a47..7dfa5fc 100644 --- a/src/services/ResponseService.php +++ b/src/services/ResponseService.php @@ -46,7 +46,7 @@ public function stream(string $config, array $store): array $content = $this->renderTemplate($config->template, $variables); - // Output any remaining content + // Output any rendered content in a fragment event. if (!empty($content)) { $this->fragment($content); } @@ -184,15 +184,15 @@ private function sendEvent(string $class, string $content = '', array $options = private function flushEvent(EventInterface $event): void { - // Capture inline content before ending output buffers + // Capture inline content before ending output buffers. $inlineContent = ob_get_contents(); - // Clean and end all existing output buffers + // Clean and end all existing output buffers. while (ob_get_level() > 0) { ob_end_clean(); } - // Output inline content as a fragment event + // Output inline content as a fragment event. if ($inlineContent !== false) { $fragment = new FragmentEvent(); $fragment->content = $inlineContent; @@ -203,8 +203,7 @@ private function flushEvent(EventInterface $event): void flush(); - // Start a new output buffer + // Start a new output buffer to capture any subsequent inline content. ob_start(); - sleep(1); } }