wanick/web-socket-queue
Composer 安装命令:
composer require wanick/web-socket-queue
包简介
PHP project for web sockets and Queue WebSockets
关键字:
README 文档
README
Usage with
Examples
use Wanick\WebSocketQueue\Drivers\SurrealDriver; // link to RCP SurrealDB $surreal = new SurrealDriver('wss://hostname:8080/rcp'); if ($surreal) { $surreal->use($config['ns'], $config['db']) ->signin([ "user" => $config['user'], "pass" => $config['pass'], ], function($resulr, $error) { // .... your code }) ->query('SELECT * FROM people WHERE ago > $ago', ['ago' => 18], function($result, $error) { // .... your code print_r($result[0]); })->exec(); }
Usage with
NATS
use Wanick\WebSocketQueue\Drivers\NatsDriver; // link to NATS Connection $nats = new NatsDriver('wss://nats.server.com:8080/nats'); if ($nats) { $nats ->pub("EVENT_NAME", ['event' => 'test', 'data' => 123]) ->pub("EVENT_NAME", ['event' => 'test', 'data' => 234]) ->exec(); }
Example listening
use Wanick\WebSocketQueue; $queue = new WebSocketQueue\Queue(); $surreal = new SurrealDriver($url); // this $surreal use + signin $nats = new NatsDriver($url); $nats->sub('ON-YOUR-CUSTOM-EVENT', null, function(string $result) use($surreal) { $data = json_decode($result, true); // if you write in JSON format to NATS switch ($data['action']) { case 'alert': $surreal->query('UPDATE table_name SET field = $value WHERE id = $id', [ 'id' => $data['id'], 'value' => 1, ]); // Add "->exec()", if you want saving right now // $queue->wait execute this query on loop break; } }); // can use // $surreal->live('table_name' ... for all table event $surreal->liveQuery('SELECT * FROM table_name WHERE field > $max', [ 'max' => 10], function ($action, $result) use($nats) { switch ($action) { case 'UPDATE': $nats->pub("ON-YOUR-CUSTOM-EVENT", ['action' => 'alert', 'id' => $result['id']]); // can be ->exec() break; default: // no action CLOSE, CREATE, CONNECT, DELETE // use CONNECT - for saving queryUuid for use liveListener or kill break; } }); $queue->registrySocket($surreal); $queue->registrySocket($nats); // Locked loop - and example max work time execute $queue->wait(fn($s) => (microtime(1) - $s < $max_work_time));
wanick/web-socket-queue 适用场景与选型建议
wanick/web-socket-queue 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.98k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 09 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ws」 「nats」 「web socket」 「surrealdb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wanick/web-socket-queue 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wanick/web-socket-queue 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wanick/web-socket-queue 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Model of a web-based resource
A nats library for Hyperf.
Nats jetstream client for Laravel
Retrieve a WebResourceInterface instance over HTTP
NO LIBRARIES socket per page bridge for your Laravel application.
Official PHP client for NATS messaging system
统计信息
- 总下载量: 12.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-19