Download the PHP package godjarvis/hyperf-sse without Composer

On this page you can find all versions of the php package godjarvis/hyperf-sse. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package hyperf-sse

Hyperf SSE

面向 Hyperf 3.1 的 Server-Sent Events(SSE)组件,提供统一的消息协议、流式响应、用户定向通知、广播通知,以及可切换的 Redis Stream / RabbitMQ 驱动。

包名:godjarvis/hyperf-sse

GitHub:GodJarvis/hyperf-sse

PHP:>= 8.1

Hyperf:~3.1.0

1. 设计定位

该组件只负责可复用的 SSE 基础设施:

组件不内置 Controller、路由或用户认证。应用必须从服务端可信的登录上下文解析 subject(用户 ID、租户用户 ID、页面会话 ID 等),不能信任客户端直接提交的用户 ID。

对于异步任务通知,推荐继续保留数据库作为事实来源:

  1. Worker 先提交任务最终状态;
  2. 再通过本组件发布轻量通知;
  3. 页面初始化及 SSE 重连后调用任务查询接口校准状态;
  4. Redis Stream 可按 Last-Event-ID 补发保留范围内的事件,但仍不替代业务数据库。

2. 安装

2.1 Packagist 发布后

Hyperf 会通过 composer.json > extra.hyperf.config 自动发现 ConfigProvider,并注册:

发布配置:

生成:

2.2 Packagist 发布前本地联调

项目与组件目录相邻时:

然后执行:

3. Redis Stream 驱动(默认)

默认配置:

特性:

默认 Key:

如果应用使用独立 Redis 连接池,先在 config/autoload/redis.php 中配置对应池,再设置 SSE_REDIS_POOL。

4. RabbitMQ 驱动(可选)

先安装 Hyperf AMQP:

配置:

RabbitMQ 驱动会为每条 SSE 连接创建一个独占、自动删除的临时队列,并绑定:

边界:

5. Controller 接入

完整示例见 examples/SseController.php。核心写法:

SseEmitter::emit() 会直接持有并结束底层 HTTP 流。调用后 Controller 必须结束执行,推荐声明返回类型为 void,不要再返回普通响应内容。

默认响应头:

6. 发布通知

定向通知:

广播:

建议只推送任务 ID、状态和结果地址等小消息,不通过 SSE 发送大文件或大型任务结果。

7. 前端 EventSource

原生 EventSource 不能自由设置 Authorization Header:

8. Nginx / Ingress

Nginx 示例:

还需要检查外层 Ingress、API 网关、CDN 或负载均衡器的响应缓冲、压缩和空闲超时。应用层心跳间隔必须小于链路中最短的空闲超时。

9. 自定义驱动

实现接口:

在 config/autoload/sse.php 注册:

subscribe() 必须返回 Generator<SseMessage>;心跳使用:

10. 从当前项目迁移

原项目概念与组件 API 对照:

原实现 组件实现
App\Service\SseService GodJarvis\HyperfSse\SseService
App\Service\Sse\SseDriverInterface GodJarvis\HyperfSse\Contract\SseDriverInterface
App\Service\Sse\SseRedisDriver GodJarvis\HyperfSse\Driver\RedisStreamDriver
App\Service\Sse\SseRabbitMqDriver GodJarvis\HyperfSse\Driver\RabbitMqDriver
SseResponseFormatTrait::sseReturn() SseEmitter::emit()
SseEvent 枚举 普通事件字符串,由业务项目自行定义枚举
uid string|int $subject,支持复合业务标识

迁移时保留业务项目自己的:

11. 开发与验证

当前测试覆盖消息格式、心跳、服务委托、驱动工厂、ConfigProvider 与 AMQP 拓扑元数据。Redis/RabbitMQ 真连接、浏览器断线、多 Worker/多实例及代理链路需要在使用方环境执行集成测试和压测。

12. 发布到 Composer

仅推送 GitHub 仓库还不足以让所有项目直接执行标准 composer require。首次发布还需要:

  1. 将代码推送到 GodJarvis/hyperf-sse;
  2. 在 Packagist 提交仓库;
  3. 配置 GitHub Webhook 或 Packagist GitHub Service;
  4. 创建语义化版本标签,例如:

发布后用一个全新目录验证:


All versions of hyperf-sse with dependencies

PHP Build Version
Package Version
Requires hyperf/codec Version ~3.1.0
hyperf/config Version ~3.1.0
hyperf/context Version ~3.1.0
hyperf/contract Version ~3.1.0
hyperf/engine Version ^2.10
hyperf/engine-contract Version ~1.14.0
hyperf/http-message Version ~3.1.0
hyperf/laminas-mime Version ^3.0
hyperf/logger Version ~3.1.0
hyperf/redis Version ~3.1.0
hyperf/support Version ~3.1.0
php Version >=8.1
psr/container Version ^1.0 || ^2.0
psr/log Version ^1.0 || ^2.0 || ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package godjarvis/hyperf-sse contains the following files

Loading the files please wait ...