hahadu/think-swoole-socket

thinkphp swoole socket 客户端&服务器订阅

v1.0.1 2021-07-04 07:42 UTC

This package is auto-updated.

Last update: 2024-09-04 14:11:28 UTC


README

thinkphp swoole socket 客户端&服务器订阅

安装

composer require hahadu/think-swoole-socket

主要类

创建类 Swoole.php

namespace app;
use Hahadu\ThinkSwooleSocket\subscribe\Swooleable;
class Swoole extends Swooleable{
    public function onConnect($data){
       //$this->push($data);
       //or
       //$this->websocket->push(json_encode($data));
    }
}

配置

编辑 swoole.php 以设置 thinkphp 配置路径

 [
 ...
  'websocket' => [
  ...
  'handler'       => Handler::class, //default
  ...
  'subscribe'     => [
            app\Swoole::class //because namespace app\Swoole
        ],
]
];

运行

控制台

php think swoole start

如果你在控制台显示

Starting swoole http server...
Swoole http server started: <http://127.0.0.1:9502> 
You can exit with `CTRL-C`

浏览器正在访问

http://127.0.0.1:9502

其他

主页

github

hahadu/think-swoole-socket

gitee

hahadu/think-swoole-socket

浏览器 JavaScript 客户端

tpswoole-websocket-jsclient