khvalov/centrifuge-php-cli

Centrifuge 2.X 客户端,用PHP编写

dev-master 2019-08-04 02:45 UTC

This package is auto-updated.

Last update: 2024-09-04 17:54:31 UTC


README

Centrifuge服务器客户端,用PHP7编写

require('./vendor/autoload.php');
use CentrifugeClient\CentrifugeClient;
$token='Your JWT Token. Feel free to use any or \Firebase\JWT libbrary to create it';

$centrifugeClient=new CentrifugeClient('ws://your-server-running-centrifuge/connection/websocket');
$centrifugeClient->setToken($token); //Put your token 

$centrifugeClient->on(CentrifugeClient::EVENT_CONNECTED,function(){
	echo "Connected"; //configuring Events if any
});

$centrifugeClient->on(CentrifugeClient::EVENT_DISCONNECTED,function($event){
	var_dump($event); //configuring Events if any
});

$centrifugeClient->subscribe('3efe3c40-c0fa-11e8-b3f4-1c51435d0814',function($message){
	echo "Beginning of process...";
	var_dump($message);
	echo "End of the process...";

});

$centrifugeClient->connect(); //running main loop

##安装##

composer install khvalov/centrifuge-php-cli 

##事件##

当前库仅支持2个事件

  • EVENT_CONNECTED
  • EVENT_DISCONNECTED

##已知限制##

是的,这是PHP,它的设计是会崩溃的(c)。使用PHP进行常量循环绝对不是一个好主意,但无论如何,这里有一些已知的限制

  • 它不支持(至少现在)通过设计取消订阅功能
  • 运行PHP 7.1+版本,因为大量使用lambda函数
  • 尚未支持重新连接(有一些想法如何实现它)
  • 尚未经过大量测试,不建议用于生产相关产品/服务
  • 仅支持WebSocket WS协议(以及很可能是WSS,但尚未测试)

欢迎任何贡献