【问题标题】:How can I do right routes and controllers with swoole in laravel?如何在 laravel 中使用 swoole 进行正确的路由和控制器?
【发布时间】:2019-08-23 23:21:59
【问题描述】:

我按照说明安装了所有东西,项目开始了:

我在 Github 上阅读了 wiki,第 7 点是这个溃败示例:

Websocket::on('connect', function ($websocket, Request $request) {
    // called while socket on connect
    $websocket->emit('message', 'hello world');
});

Websocket::on('disconnect', function ($websocket) {
    // called while socket on disconnect
});

Websocket::on('example', function ($websocket, $data) {
    $websocket->emit('message', 'response from example action');
});

Websocket::on('message', function ($websocket, $data) {
    $websocket->emit('message', 'response from message action');
    // $websocket->push('message', 'response from message action by push');
});

Websocket::on('test', 'Users/Telegram@connectServers');
Websocket::on('joinToRoom', 'Users/Telegram@joinToRoom');

现在,当它连接时(我使用this 进行测试)只有一条消息hello word,而我过去发送的每条消息都没有答案。

为什么?

如何在 laravel 中使用 swoole 做正确的路由和控制器?

【问题讨论】:

    标签: php laravel sockets swoole


    【解决方案1】:

    同样的问题。尝试为控制器放置完整的命名空间。

    类似:

    Websocket::on('test', '\App\Http\Controllers\Users\Telegram@connectServers');
    

    如果它与缩短的形式一起使用会很棒。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-27
      • 2023-03-27
      • 2017-03-05
      • 1970-01-01
      • 2014-03-05
      • 2014-08-20
      • 1970-01-01
      相关资源
      最近更新 更多