ashiina/socket.io-emitter

*维护中* socket.io-emitter 的 PHP 实现

0.8.0 2016-06-06 04:59 UTC

This package is not auto-updated.

Last update: 2024-09-20 18:48:39 UTC


README

Build Status

维护分支

这是一个对 rase-/socket.io-php-emitter 的分支。
由于原始仓库不再维护,并且与新版本的 Socket.io 存在兼容性问题,我建议使用此仓库,并且在此处提交问题。

@ashiina

socket.io-php-emitter

socket.io-emitter 的 PHP 实现。

安装和设置

1. socket.io-php-emitter

要将它安装并用于您的 PHP 项目,请将其作为 composer 包 安装。使用 composer install 安装依赖项。

2. Redis 服务器

您需要一个 Redis 服务器来发射事件。设置您的 Redis 服务器。

3. socket.io-redis (node.js)

要接收发射的事件,您需要使用 socket.io-redis。它将自动处理从 socket.io-php-emitter 发射的事件。从这里安装和设置: https://npmjs.net.cn/package/socket.io-redis

用法

初始化

$redis = new \Redis(); // Using the Redis extension provided client
$redis->connect('127.0.0.1', '6379');
$emitter = new SocketIO\Emitter($redis);
$emitter->emit('event', 'payload str');

广播和其他标志

可能的标志

  • json
  • volatile
  • broadcast
// Below initialization will create a  phpredis client, or a TinyRedisClient depending on what is installed
$emitter = new SocketIO\Emitter(array('port' => '6379', 'host' => '127.0.0.1'));
// broadcast can be replaced by any of the other flags
$emitter->broadcast->emit('other event', 'such data');

发射对象

$emitter = new SocketIO\Emitter(); // If arguments are not provided, they will default to array('port' => '6379', 'host' => '127.0.0.1')
$emitter->emit('event', array('property' => 'much value', 'another' => 'very object'));

关于 PHP Redis 客户端

此项目需要一个 PHP Redis 客户端。如果您没有安装 PECL Redis,发射器将默认使用 TinyRedisClient。但是,您可以传递任何支持 publish 方法的 Redis 客户端。

开发

要运行测试,请调用 make test。当前的测试套件将仅检查 Redis 监视器,以确保所有发布的事件都正确。在不久的将来,将投入更多精力以创建更好的集成测试套件。