Skip to content

Commit

Permalink
Better code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Oct 31, 2024
1 parent b3a92d1 commit 5210e31
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/controllers/ResponseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
11 changes: 5 additions & 6 deletions src/services/ResponseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}

0 comments on commit 5210e31

Please sign in to comment.