Skip to content

Commit

Permalink
Merge pull request #22 from Fohn-Group/fixes/sse
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
ibelar authored Mar 24, 2024
2 parents 23ee4be + 79168e2 commit a38181f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions app-test/_includes/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static function createPage(string $environment = 'production'): Page
]);

if ($environment === 'dev') {
$page->fohnJsVersion = '';
$page->includeJsPackage('fohn-js', '/public/fohn-ui.js');
$page->includeCssPackage('fohn-css', '/public/fohn-ui.css');
}
Expand Down
1 change: 1 addition & 0 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public function prepareEventStreaming(int $limit = 0, bool $ignoreUserAbort = tr
{
@set_time_limit($limit);
ignore_user_abort($ignoreUserAbort);
@ini_set('zlib.output_compression', '0');

$response = (new Response())
->withHeader('Content-Type', 'text/event-stream')
Expand Down
8 changes: 7 additions & 1 deletion src/Callback/ServerEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class ServerEvent extends Generic
/** Keep execution alive or not if connection is close by user. False mean that execution will stop on user aborted. */
public bool $keepAlive = false;

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

/** Check if ServerEvent callback has been request and executed. */
private bool $requestSet = false;

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

$this->app->streamEvent($streamEvent);
Expand Down

0 comments on commit a38181f

Please sign in to comment.