hahadu/think-swoole-socket

thinkphp swoole socket client&server subscribe

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

This package is auto-updated.

Last update: 2024-04-04 13:23:02 UTC


README

thinkphp swoole socket client&server subscribe

install

composer require hahadu/think-swoole-socket

main class

create class 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));
    }
}

config

edit swoole.php for thinkphp config path

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

run

console

php think swoole start

if you console show

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

browser going

http://127.0.0.1:9502

other

home page :

github

hahadu/think-swoole-socket

gitee:

hahadu/think-swoole-socket

browser javascript client:

tpswoole-websocket-jsclient