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

时间:2019-03-09 22:02:05

标签: php websocket ratchet phpwebsocket

使用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错误和会话超时的合适方法?

0 个答案:

没有答案