workerman v5.0.0-beta.8 创建websocket不生效,客户端发不过去消息,使用工具好久才能连上,
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Request;
use Workerman\Worker;
$worker = new Worker('websocket://0.0.0.0:22004');
$worker->onMessage = function (TcpConnection $connection, $data) {
var_dump($data);
//$connection->send('receive success');
};
$worker->onWorkerStart = function ($worker) {
echo 'Worker start success';
};
$worker->onWebSocketConnect = function (TcpConnection $connection, Request $request) {
echo 'WebSocket connection success';
};
Worker::runAll();
先创建websocket,在创建异步发送客户端,发送不管用,服务端收不到
workerman v5.0.0-beta.8 php 8.2.17
前端代码呢?
解决了,后来发现是global的问题,连接不能使用global,只能传过去,因为是在workerstart里面起的异步tcp