roman444uk / yii2-sse
该软件包最新版本(v1.0.1)没有提供许可证信息。
Yii2 SSE 是对 libSSE-php 库的封装。它用于在 Yii2 中管理服务器端事件。
v1.0.1
2023-06-22 23:15 UTC
Requires
- roman444uk/sse: *
- yiisoft/yii2: ^2.0
This package is not auto-updated.
Last update: 2024-09-28 03:17:52 UTC
README
Yii2 SSE 是对 libSSE-php 库的封装。它用于在 Yii2 中管理服务器端事件。
安装
您将通过 composer 安装此软件包。
在项目文件夹中运行此命令: composer require roman444uk/yii2-sse
用法
以下步骤适用于简单的/基本的 Yii2 项目。
编辑您的 web.php 配置文件,通常位于 app/config/web.php
'components' => [ ... 'sse' => [ 'class' => \roman444uk\Yii2SSE\LibSSE::class ] ... ];
您需要为您的 SSE 实例创建一个处理器。通常位于 app/sse/。
use roman444uk\Yii2SSE\SSEBase; class MessageEventHandler extends SSEBase { public function check() { return true; } public function update() { return "Something Cool"; } }
然后,在控制器中的任何地方
public function actionIndex() { $sse = Yii::$app->sse; $sse->addEventListener('message', new MessageEventHandler()); $sse->start(); }
更多信息
有关使用此软件包的 SSE 功能的更多信息,请访问:https://github.com/licson0729/libSSE-php