inhere/websocket
Composer 安装命令:
composer require inhere/websocket
包简介
a lightweight webSocket application library, server and client by sockets,streams,swoole
README 文档
README
a lightweight webSocket application library
install
in composer.json add:
"inhere/websocket": "dev-master",
run: composer up
usage
only use webSocket server
use Inhere\WebSocket\WebSocketServer; $ws = new WebSocketServer(); $ws->on('open', function (WebSocketServer $ws, $data) { $ws->send('welcome!'); }); $ws->on(WebSocketServer::ON_MESSAGE, function (WebSocketServer $ws, $data) { $ws->send("you input: $data"); }); $ws->start();
use the webSocket application
use Inhere\WebSocket\Application; use Inhere\WebSocket\WebSocketServer; $app = new Application('', 9501); $app->onOpen(function (WebSocketServer $ws, Application $app, $id) { $app->respond([ 'total' => $ws->count() ], 'welcome!'); }); $app->onClose(function (WebSocketServer $ws, Application $app) { $app->respond([ 'total' => $ws->count() ]); }); $rootHandler = $app->route('/', new \Inhere\WebSocket\handlers\RootHandler()); // commands $rootHandler->add('test', function ($data, $index, Application $app) { return 'hello'; });
webSocket header example
webSocket request header
// parsed code
GET / HTTP/1.1
Host: 127.0.0.1:9501
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: http://localhost:63342
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3018.3 Safari/537.36
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: zh-CN,zh;q=0.8
Cookie: _ga=GA1.1.1542925283.1469426767
Sec-WebSocket-Key: Tak3+4p37S5EAltSHDxpTw==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
// source code
GET ws://127.0.0.1:9501/ HTTP/1.1
Host: 127.0.0.1:9501
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: http://localhost:63342
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3018.3 Safari/537.36
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: zh-CN,zh;q=0.8
Cookie: _ga=GA1.1.1542925283.1469426767
Sec-WebSocket-Key: BmMdv63hr1D/eS7eTD59Vw==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
webSocket response header(handshake success)
// parsed code
Connection:Upgrade
Sec-WebSocket-Accept:BOVf/XCi92SSib4Ga+ltTsmHiWQ=
Upgrade:websocket
// source code
HTTP/1.1 101 Switching Protocol
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: BOVf/XCi92SSib4Ga+ltTsmHiWQ=
license
MIT
inhere/websocket 适用场景与选型建议
inhere/websocket 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37 次下载、GitHub Stars 达 4, 最近一次更新时间为 2017 年 03 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「websocket」 「library」 「sockets」 「Streams」 「swoole」 「webSocket-application」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 inhere/websocket 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 inhere/websocket 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 inhere/websocket 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Synchronous Message Passing Framework for PHP
Thruway WAMP router core
Inbox pattern process implementation for your Laravel Applications
Binding for raw sockets (ext-sockets) in reactphp
NO LIBRARIES socket per page bridge for your Laravel application.
Core library that defines common interfaces used by the rest of the intahwebz..
统计信息
- 总下载量: 37
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-03-29