rapsspider/cake_ratchet 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rapsspider/cake_ratchet

Composer 安装命令:

composer require rapsspider/cake_ratchet

包简介

Ratchet Plugin for CakePHP 3.X

README 文档

README

Requirements

ZeroMQ : http://www.zeromq.org/

Installation

composer require rapsspider/cake_ratchet

Configuration

Add this at the end of your config\app.php file:

/**
 * Ratchet configuration
 */
'CakeRatchet' => [
    'Server' => [
        'host' => '0.0.0.0',
        'port' => 8080
    ],
    'ZMQServer' => [
        'host' => '127.0.0.1',
        'port' => 5555
    ],
    'JSHelper' => true
]

Add this in your config\bootstrap.php file:

Plugin::load('CakeRatchet', ['bootstrap' => true]);

It's possible you need to add this on your vendors/cakephp-plugins.php file:

...
'plugins' => [
    ...
    'CakeRatchet' => $baseDir . '/vendor/rapsspider/cake_ratchet/',
    ...
]

Start

First, you need to start the server, to do this just run this command on your cakephp folder : .\bin\cake ratchet start

Examples

Server

namespace App\Controller;
use (@TODO)\Pusher;

public class MyController {

    public function index() {
        Pusher::send('my_topic','my_message');
    }
    
}

Client

If JSHelper is activate, an fonction will be available:

<script>
var onConnect = function(connection) {
    connection.subscribe('my_topic', function(topic, data) {
        // This is where you would add the new article to the DOM (beyond the scope of this tutorial)
        console.log('New article published to category "' + topic + '" : ');
        console.log(data);
    });
};

var onClose = function(connection) {

};

CakeRatchet.connection(onConnect, onClose); 
</script>

Else, you can do this :

<script src="http://autobahn.s3.amazonaws.com/js/autobahn.min.js"></script>
<script>
	var conn = new ab.Session('ws://localhost:8080',
		function() {
			conn.subscribe('my_topic', function(topic, data) {
				// This is where you would add the new article to the DOM (beyond the scope of this tutorial)
				console.log('New article published to category "' + topic + '" : ');
				console.log(data);
			});
			console.log('Connexion réussie');
		},
		function() {
			console.warn('WebSocket connection closed');
		},
		{'skipSubprotocolCheck': true}
	);
</script>

统计信息

  • 总下载量: 30
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固