使用 ratchetphp/Pawl websocket 客户端的问题

Issues using ratchetphp/Pawl websocket client

我的问题特定于在 ratchetphp/Pawl 上使用 slack rtm。我有以下代码可以正常连接但最终会死掉。

            <?php

            require_once "response.php";

            //first make authenticated call to rtm.start    
            use \Curl\Curl;
            $curl = new Curl();

            $rtmStartUrl = "https://slack.com/api/rtm.start?token=xx-xx-xx-xx-xx&pretty=1";
            $curl->get($rtmStartUrl);

            $wsUrl = $curl->response->url;

            $loop = React\EventLoop\Factory::create();
            $connector = new Ratchet\Client\Connector($loop);

            $connector($wsUrl)
            ->then(function(Ratchet\Client\WebSocket $conn) {
            $conn->on('message', function(\Ratchet\RFC6455\Messaging\MessageInterface $msg) use ($conn) {
            echo "Received: {$msg}\n";
            // $conn->close();
            });

            $conn->on('close', function($code = null, $reason = null) {
            echo "Connection closed ({$code} - {$reason})\n";
            });

            $conn->send('Hello World!');
            }, function(\Exception $e) use ($loop) {
            echo "Could not connect: {$e->getMessage()}\n";
            $loop->stop();
            });

            $loop->run();

在 运行 上,输出为:

            root@ip-172-31-45-75:/var/www/html/slack# php pawl.php 
            Received: {"type":"hello"}
            Received: {"type":"reconnect_url","url":"wss://mpmulti-qpau.slack-msgs.com/websocket/jDkgDysXfZspRj10zqdcrshHK6PhPLItYx2HEkdXy47RPCAJwKgI_NLq0bhS4uMjIT7iRtOoCDUJffcxcr7YdiqMbITUZYqnTmT39Et5a8JeuPLFfCUUzan4MCz34p0jcfAKaQW9G9HpIWrYH4CTqyICZuhgWHnzo8K7dO2zXFc="}
            Received: {}
            Connection closed (1006 - Underlying connection closed)
            root@ip-172-31-45-75:/var/www/html/slack# 

websocket 是通过 websocket 发送的 slack rtm api (https://api.slack.com/rtm). It seems like when reading on empty websocket, the connection is closed. I think it might be like we listen to slack events (https://api.slack.com/events) 的一部分,用于避免断开连接。

目前,由于断开连接错误,这不起作用。

Hello World! 不是此 API 的有效消息,因此 Slack 在收到该消息时正在关闭连接。尝试发送有效的内容(或根本不发送任何内容)。