workerman v5.0.0-beta.8 创建websocket不生效,客户端发不过去消息

Taotao

问题描述

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/webman等具体版本

workerman v5.0.0-beta.8 php 8.2.17

330 1 0
1个回答

walkor 打赏

前端代码呢?

  • Taotao 2024-09-28

    解决了,后来发现是global的问题,连接不能使用global,只能传过去,因为是在workerstart里面起的异步tcp

×
🔝