wyrihaximus / ratchet-commands
为 wyrihaximus/ratchet 带来双向通信。
0.1.0
2015-01-22 16:05 UTC
Requires
- php: >=5.4.0
- composer/installers: *
- wyrihaximus/ratchet: ^0.1
Requires (Dev)
- predis/predis: 0.8.*
Suggests
- dnode/dnode: Send commands to the Ratchet service over simple pure PHP sockets
- predis/predis: Send commands to the Ratchet service over redis
- predis/predis-async: Send commands to the Ratchet service over redis
- react/zmq: Send commands to the Ratchet service over 0MQ
This package is auto-updated.
Last update: 2024-09-04 19:30:09 UTC
README
RatchetCommands 允许您的应用程序将消息发送到 Ratchet 服务器实例。
入门指南
1. 要求
此插件依赖于以下插件和库,并由 composer 在稍后拉入
2. Composer
请确保您已安装并配置了 composer,并在引导过程中注册了自动加载器,如此处所述。请确保您有一个 composer.json 文件,并在您的需求部分添加以下内容。
composer require wyrihaximus/ratchet-commands
3. 设置插件
请确保在引导中加载 RatchetCommands
,并且 Ratchet
插件已正确设置。
4. 构建命令
文件名:Lib/MessageQueue/Command/BroadcastCommand.php
class BroadcastCommand extends RatchetMessageQueueCommand { public function serialize() { return serialize(array( 'data' => $this->data, )); } public function unserialize($commandString) { $commandString = unserialize($commandString); $this->setData($commandString['data']); } public function setData($data) { $this->data = $data; } public function getData() { return $this->data; } // Send a broadcast on the channel `channel` with the data sent with the command // (This runs in the Ratchet instance.) public function execute($eventSubject) { $topics = $eventSubject->getTopics(); if (isset($topics['channel'])) { $topics['channel']->broadcast($this->getData()); } return true; } // Handle the response // (This runs in the application.) public function response($response) { if ($response) { // Handle success } else { // Handle failure } } }
请确保在引导中使用 App::uses 调用命令,以便 Ratchet 实例知道从哪里加载它。
5. 发送消息
App::uses('TransportProxy', 'RatchetCommands.Lib/MessageQueue/Transports'); $command = new BroadcastCommand(); $command->setData([ 'time' => time(), ]); TransportProxy::instance()->queueMessage($command);
插件许可证
(MIT 许可证)
版权 © 2012 - 2013 Cees-Jan Kiewiet
特此授予任何获取此软件及其相关文档副本(“软件”)的人无限制地处理软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并允许向软件提供的人这样做,前提是遵守以下条件
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
软件按“原样”提供,没有任何形式的保证,明示或暗示,包括但不限于适销性、针对特定目的的适用性和非侵权性。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论这些责任是基于合同、侵权或其他方式产生的,无论这些责任是否与软件或其使用或其他方式有关。