Skip to content

Commit

Permalink
Merge pull request #23 from Fohn-Group/improve-buffer-handling-sse
Browse files Browse the repository at this point in the history
improve buffer size handling for SSE
  • Loading branch information
ibelar authored Mar 27, 2024
2 parents a38181f + d3464c6 commit 77ec4a6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ public function isConnectionAborted(): int
/**
* Output Server side event to client.
*/
public function streamEvent(array $event): void
public function streamEvent(array $event, int $bufferSize = 0): void
{
foreach ($event as $v) {
echo $v;
echo $v .= ': ' . str_pad('x', $bufferSize) . "\n\n";
}

flush();
Expand Down
8 changes: 4 additions & 4 deletions src/Callback/ServerEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class ServerEvent extends Generic
public bool $keepAlive = false;

/**
* The min size of event stream data to be output.
* Set it to 4096 when using phpfpm.
* The min size of event stream data buffer.
* Set it to 4096 when using phpfpm with apache mod_proxy_fcgi.
*/
public int $minBufferSize = 0;

Expand Down Expand Up @@ -133,10 +133,10 @@ protected function sendBlock(string $id, string $event, string $name): void
$streamEvent = [
'id: ' . $id . "\n",
'event: ' . $name . "\n",
'data' => $this->wrapEvent(str_pad($event, $this->minBufferSize)) . "\n",
'data' => $this->wrapEvent($event) . "\n",
];

$this->app->streamEvent($streamEvent);
$this->app->streamEvent($streamEvent, $this->minBufferSize);
}

public function start(JsStatements $statements = null): JsRenderInterface
Expand Down
2 changes: 1 addition & 1 deletion tests/Callback/MockApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function callExit(): void
{
}

public function streamEvent(array $event): void
public function streamEvent(array $event, int $bufferSize = 0): void
{
}
}

0 comments on commit 77ec4a6

Please sign in to comment.