skorovodkin/socket.io-emitter

socket.io-emitter 的 PHP 实现

0.8.1 2016-03-29 09:22 UTC

This package is not auto-updated.

Last update: 2024-09-20 19:55:41 UTC


README

socket.io-emitter 的 PHP 实现(0.2.0)支持命名空间。

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

安装和开发

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

要运行测试,请调用 make test。当前的测试套件将仅检查 Redis 监视器以确保所有内容都正确发布。未来将投入一些工作以创建更好的集成测试套件。

使用方法

初始化

$redis = new \Redis(); // Using the Redis extension provided client
$redis->connect('127.0.0.1', '6379');
$emitter = new SocketIO\Emitter($redis);
$emitter->of('namespace')->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'));