ratchetphp/Pawl 连接关闭 (1009 - ) FRAME::CLOSE_TOO_BIG = 1009

Posted

技术标签:

【中文标题】ratchetphp/Pawl 连接关闭 (1009 - ) FRAME::CLOSE_TOO_BIG = 1009【英文标题】:ratchetphp/Pawl Connection closed (1009 - ) FRAME::CLOSE_TOO_BIG = 1009 【发布时间】:2019-03-09 22:02:04 【问题描述】:

我很高兴能使用 Pawl,它可以处理小文件(例如 350 KB)。

但是,当我通过$fullFileName 发送一个更大的文件(例如,30 MB)时,如下所示,我收到此错误:Connection closed (1009 - )

\Ratchet\Client\connect($url)->then(function(\Ratchet\Client\WebSocket $conn) use($contentType, $fullFileName) 
    $conn->on('message', function($msg) use ($conn) 
        Log::debug("Received: $msg");
    );
    $conn->on('close', function($code = null, $reason = null) 
        Log::debug("Connection closed ($code - $reason)");
    );
    $conn->send(json_encode([
        'content-type' => $contentType,
        'timestamps' => true,
        'speaker_labels' => true,
        'smart_formatting' => true,
        'inactivity_timeout' => 60 * 5,
        'x-watson-learning-opt-out' => true,
        'action' => 'start'
    ]));

    $frame = new \Ratchet\RFC6455\Messaging\Frame(file_get_contents($fullFileName), true, \Ratchet\RFC6455\Messaging\Frame::OP_BINARY);
    $binaryMsg = new \Ratchet\RFC6455\Messaging\Message();
    $binaryMsg->addFrame($frame);
    $conn->send($binaryMsg);
    $conn->send(json_encode([
        'action' => 'stop'
    ]));
, function ($e) 
    echo "Could not connect: $e->getMessage()\n";
);

当我搜索Frame::CLOSE_TOO_BIG 的用法时,我发现它只被\Ratchet\RFC6455\Messaging\CloseFrameChecker 使用过。

但我一直无法弄清楚\Ratchet\RFC6455\Messaging\CloseFrameChecker 的工作原理、文件大小限制以及如何发送大文件。

我尝试首先使用str_split 将我的文件拆分为多个块,然后添加单独的帧,但是我每次都会遇到会话超时,即使是小文件也是如此。

什么是发送较大文件的适当方法,避免Frame::CLOSE_TOO_BIG 1009 错误和会话超时?

【问题讨论】:

【参考方案1】:

https://cloud.ibm.com/apidocs/speech-to-text 和 https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-websockets#WSreturn 说 1009 = 由于帧大小超过 4 MB 限制,连接已关闭。

所以我尝试将音频文件拆分为单独的帧。我的第一次尝试总是导致 "Session timed out." 错误。

https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-input#timeouts 说:

在发送最后一个块以指示流结束后,您无需担心会话超时。该服务会继续处理音频,直到它返回最终的转录结果。当您转录较长的音频流时,该服务可能需要 30 多秒的时间来处理音频并生成响应。该服务在完成处理它收到的所有音频之前不会开始计算会话超时。服务的处理时间不会导致会话超过 30 秒的会话超时。

这是似乎对我有用的代码:

/**
 * @param \Ratchet\Client\WebSocket $conn
 * @param string $fileContents
 */
public function sendBinaryMessage($conn, $fileContents) 
    $chunks = str_split($fileContents, 100);
    Log::debug('Split audio into this many frames: ' . count($chunks));
    $final = true;
    foreach ($chunks as $key => $chunk) 
        Log::debug('send chunk key ' . $key);
        $frame = new \Ratchet\RFC6455\Messaging\Frame($chunk, $final, \Ratchet\RFC6455\Messaging\Frame::OP_BINARY);
        $conn->send($frame);
    

【讨论】:

以上是关于ratchetphp/Pawl 连接关闭 (1009 - ) FRAME::CLOSE_TOO_BIG = 1009的主要内容,如果未能解决你的问题,请参考以下文章

100 个用户工作正常,对于 200 个用户,它会给出“javax.net.ssl.SSLHandshakeException”错误,并显示“握手期间远程主机关闭连接”消息

FTP登陆 出现] 连接被关闭;传输已放弃

HikariCP 未在 close() 上关闭连接(连接泄漏)

Django:Postgres 连接未关闭

Nginx上游过早关闭连接,同时从上游形式Node js rocky proxy读取响应头

随机 SSL 日志“AH01998:连接关闭到子进程并中断关闭”apache