国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

關(guān)于workerman/http-client的一個疑問

島嶼可以找到海

問題描述

$http->request($host.$url, [
            'method' => 'POST',
            'data' => json_encode($data),
            'headers' => $header,
            'progress' => function ($buffer) use ($userConnection, $http) {

                if ($http->incompleteData!=""){
                    $buffer=$http->incompleteData.$buffer;//將上次不完整數(shù)據(jù)和本次不完整數(shù)據(jù)拼接
                    $http->incompleteData='';//重置不完整數(shù)據(jù)
                }

                $result = $this->parsedData($buffer);

                $content=$result['content'];

                $incompleteData=$result['incompleteData'];//不完整數(shù)據(jù)
                if ($incompleteData!=""){
                    $http->incompleteData.=$incompleteData;//設(shè)置不完整數(shù)據(jù)
                }
                if ($content!="") {
                        $userConnection->send(new Chunk($content));
                        $http->buffer .= $content;
                        $http->incompleteData='';
                }

            },
            'success' => function ($response) use ($userConnection, $http,$model,$saveMessage_callback, $deduction_callback,$updateKey_callback) {
                $userConnection->send(new Chunk(''));
                call_user_func($saveMessage_callback, $http->buffer);
                $error=json_decode($http->buffer,true);

                // 扣費(fèi)
                if ($response->getStatusCode() == 200&&!is_array($error)) {
                  //響應(yīng)200且不能是json格式,因?yàn)橛袝r候響應(yīng)200但是時間是不是正常回復(fù)
                   call_user_func($deduction_callback);
                   Redis::incr($model);//記錄相應(yīng)模型使用次數(shù)
                 }
                //更新key的使用時間
                call_user_func($updateKey_callback);

            },'error' => function ($exception)use($userConnection,$updateKey_callback,$http,$saveMessage_callback) {
                $userConnection->send(new Chunk(''));
                call_user_func($updateKey_callback);
                //錯誤或者超時也保存聊天記錄
                call_user_func($saveMessage_callback, $http->buffer);
        }
        ]);

上述代碼無法正常發(fā)送chunk響應(yīng)給客戶端,但是如果加一個print打印,那么客戶端就能收到響應(yīng)

$http->request($host.$url, [
            'method' => 'POST',
            'data' => json_encode($data),
            'headers' => $header,
            'progress' => function ($buffer) use ($userConnection, $http) {

            print_r($buffer);//這里打印一下,前端就可以接受到chunk響應(yīng)

                if ($http->incompleteData!=""){
                    $buffer=$http->incompleteData.$buffer;//將上次不完整數(shù)據(jù)和本次不完整數(shù)據(jù)拼接
                    $http->incompleteData='';//重置不完整數(shù)據(jù)
                }
                $result = $this->parsedData($buffer);
                $content=$result['content'];
                $incompleteData=$result['incompleteData'];//不完整數(shù)據(jù)
                if ($incompleteData!=""){
                    $http->incompleteData.=$incompleteData;//設(shè)置不完整數(shù)據(jù)
                }
                if ($content!="") {
                        $userConnection->send(new Chunk($content));
                        $http->buffer .= $content;
                        $http->incompleteData='';
                }
            },
            'success' => function ($response) use ($userConnection, $http,$model,$saveMessage_callback, $deduction_callback,$updateKey_callback) {
                $userConnection->send(new Chunk(''));
                call_user_func($saveMessage_callback, $http->buffer);
                $error=json_decode($http->buffer,true);
                // 扣費(fèi)
                if ($response->getStatusCode() == 200&&!is_array($error)) {
                  //響應(yīng)200且不能是json格式,因?yàn)橛袝r候響應(yīng)200但是時間是不是正?;貜?fù)
                   call_user_func($deduction_callback);
                   Redis::incr($model);//記錄相應(yīng)模型使用次數(shù)
                 }
                //更新key的使用時間
                call_user_func($updateKey_callback);
            },'error' => function ($exception)use($userConnection,$updateKey_callback,$http,$saveMessage_callback) {
                $userConnection->send(new Chunk(''));
                call_user_func($updateKey_callback);
                //錯誤或者超時也保存聊天記錄
                call_user_func($saveMessage_callback, $http->buffer);
        }
        ]);

這是什么原因呢?

破案了與程序無關(guān),是第三方接口的問題...

814 1 0
1個回答

Gin

應(yīng)該先返回個 chunk信息通知請求端 后續(xù)通過 progress返回
return response()->withHeaders([
"Content-Type" => "application/json",
"Transfer-Encoding" => "chunked",
]);
http://www.wtbis.cn/doc/workerman/components/workerman-http-client.html

  • 島嶼可以找到海 2024-06-25

    我代碼沒截完整,我寫了這個響應(yīng)了
    return response()->withHeaders([
    "Content-Type" => "application/json",
    "Transfer-Encoding" => "chunked",
    ]);
    ,如果沒加這個響應(yīng)頭,那我就算寫了print打印前端也無法接受到響應(yīng)啊

  • 島嶼可以找到海 2024-06-25

    不能啊,親測加一個print或者別的一個什么別的操作,前端就都能收到響應(yīng),我查了一下貌似和緩沖區(qū)有關(guān)系

  • Gin 2024-06-25

    走nginx代理沒有 proxy_buffering off; 有沒有

  • 島嶼可以找到海 2024-06-25

    proxy_buffering off設(shè)置了
    但是我目測和NGINX無關(guān),我本地測試也會出現(xiàn)這個問題

  • 島嶼可以找到海 2024-06-25

    破案了,是第三方接口的問題,請求空回復(fù)的時候是第三方接口報500了......

??