upsub/client

UpSub的PHP客户端。一个高性能的Web和云端的发布/订阅消息服务器。

v0.2.0 2018-03-15 09:14 UTC

This package is not auto-updated.

Last update: 2024-09-21 04:49:58 UTC


README

Latest Stable Version Build Status

这是UpSub的PHP客户端,它通过http协议与Dispatcher进行通信。此客户端仅支持写入,因此无法监听来自Dispatcher的消息。

只有支持订阅的客户端才能监听消息,请参阅JavaScript客户端

安装

客户端已发布到Packagist,可以使用composer进行安装。

composer require upsub/client

用法

<?php
use UpSub\Client;

$client = new Client('https://:4400', [
  // options
]);

选项

  • name: string:连接名称,用于调试。
  • appID: string:用于Dispatcher身份验证的应用标识符。
  • secret: string:用于身份验证的密钥。
  • timeout: int:如果http请求超时,则终止请求,默认为5秒。

创建通道

最佳方法是使用不同的通道来组织事件流。

<?php
// Single channel
$channel = $client->channel('channel');

// Multiple channels
$multiChannel = $client->channel('channel-1', 'channel-2');

发送消息

向UpSub Dispatcher发送消息。

<?php
// Send message from the channel
$channel->send('event', [ 'key' => 'value' ]);

// Send message directly from client
$client->send('event', 'my message...');

许可证

MIT许可证下发布