odannyc / yii2-sse
Yii2 SSE is a wrapper for the library libSSE-php. Its used for managing Server Sent Events in Yii2.
Installs: 25 019
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 3
Forks: 0
Open Issues: 1
Requires
- tonyhhyip/sse: ^2.1
- yiisoft/yii2: ^2.0
This package is auto-updated.
Last update: 2024-11-07 05:06:32 UTC
README
Yii2 SSE is a wrapper for the library libSSE-php. Its used for managing Server Sent Events in Yii2.
Installation
You'll be installing this package through composer.
Run this command within your project folder: composer require odannyc/yii2-sse
Usage
These steps are for the simple/basic Yii2 project.
Edit your web.php
config file which is located usually in app/config/web.php
'components' => [ ... 'sse' => [ 'class' => \odannyc\Yii2SSE\LibSSE::class ] ... ];
You'll have to create a handler for your SSE instance. Usually located in app/sse/
.
use odannyc\Yii2SSE\SSEBase; class MessageEventHandler extends SSEBase { public function check() { return true; } public function update() { return "Something Cool"; } }
Then, anywhere in your controller:
public function actionIndex() { $sse = Yii::$app->sse; $sse->addEventListener('message', new MessageEventHandler()); $sse->start(); }
More information
For more information on using the SSE functionalites of this package visit: https://github.com/licson0729/libSSE-php