gockets-project/gockets-php
Composer 安装命令:
composer require gockets-project/gockets-php
包简介
PHP client for Gockets https://github.com/gockets-project/gockets
README 文档
README
Gockets is daemon written in Golang to give languages, like PHP a middleware for REST-oriented communication with Websockets.
Gockets PHP
This library provides implemented and ready to use interface for gockets daemon.
Installation via Composer
composer require gockets-project/gockets-php
Quickstart
Setup Gockets server
Setup PHP client
use Gockets\Client; use Gockets\Model\Params; $host = 'localhost'; // Default value $port = '8844'; // Default value $client = new Client(new Params($host, $port));
Prepare channel
Creates new channel. Can accept optional argument instance of Gockets\Model\ChannelOptions.
use Gockets\Model\ChannelOptions; $options = new ChannelOptions('http://localhost/hook.php', 'tag'); // Using $client from previous sample $channel = $client->prepare($options);
Gockets\Model\Сhannel example:
object(Gockets\Model\Channel) { ["publisherToken":private] => string(32) "f177965656399535ea241a3da40dfcbf" ["subscriberToken":private] => string(32) "90b09a2e2d43c83ed907854a46c710fd" ["hookUrl":private] => string(25) "http://localhost/hook.php" ["tag":private] => string(3) "tag" ["listeners":private] => int(0) }
Show channel
Returns specific channel.
$publisherToken = '95e9aca9575c29ca8cdc92e54767d783'; $channel = $client->show($publisherToken);
Show all channels
Returns empty or filled with Gockets\Model\Сhannel objects array.
$channels = $client->showAll();
Edit channel
Use to modify specific channel attributes (change hook url or tag).
use Gockets\Model\ChannelOptions; $options = new ChannelOptions('http://localhost/new_hook.php', 'someApplication|tagged'); $updatedChannel = $client->update($channel->getPublisherToken(), $options);
Publish data
Send some data to channel.
In this example $channel variable contains Gockets\Model\Сhannel object.
$data = [ 'data' => 'content', ]; $response = $client->publish($data, $channel->getPublisherToken());
Gockets\Model\Response $response example:
object(Gockets\Model\Response) { ["success":private] => bool(true) ["type":private] => string(3) "INF" ["message":private] => string(38) "Successfully pushed data to subscriber" }
Always try to ensure that $success property of response is true.
Close channel
Closes connection and removes channel.
$response = $client->close($channel->getPublisherToken()); echo $response->getMessage(); // Outputs "Successfully closed connection"
Error handling
Mostly error handling currently in development, but in case if publisher token was not found library throws Gockets\Exception\ChannelNotFoundException.
use Gockets\Exception\ChannelNotFoundException; try { $client->show('some-publisher-token'); } catch (ChannelNotFoundException $exception) { // Your logic when publisher token was not found }
In bin directory located Gockets builded instance for Linux. For more information about Golang project refer to it's page.
gockets-project/gockets-php 适用场景与选型建议
gockets-project/gockets-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 41 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 04 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「websocket」 「Socket」 「gockets」 「php websocket」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gockets-project/gockets-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gockets-project/gockets-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gockets-project/gockets-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
NO LIBRARIES socket per page bridge for your Laravel application.
WebSocket view engine
Free PHP WebSocket
A light weight PHP http client implements PSR7, use socket/curl for sending requests.
This is a PHP Framework base on Swoole
Está é uma biblioteca genérica voltada a efetuar testes/verificação de conectividade
统计信息
- 总下载量: 41
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-30