hahadu / think-swoole-socket
thinkphp swoole socket client&server subscribe
v1.0.1
2021-07-04 07:42 UTC
Requires
- topthink/think-swoole: >=4.0
Requires (Dev)
- php: >=7.4
- ext-redis: *
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 :