首页 > 其他分享 >GuzzleHttp 超时后处理

GuzzleHttp 超时后处理

时间:2023-11-07 14:13:56浏览次数:35  
标签:body dump 后处理 json timeout var 超时 GuzzleHttp

 

 public function httpTest()
    {
        $url = "自己可以写一个模拟地址,例如下面的 httpTest2 先让他挂起一定的时间,timeout设置超时时间,如果超过timeout的时间 会自动抛出异常,去发短信等...";

        $client   = new Client();
        try {
                $response = $client->request('POST', $url, [
                'headers' => ['Content-Type' => 'application/json'],
                'json'    => [1,2,3,4,5,6],
                'timeout' => 5
                //                "debug"=>true
            ]);
            $body = $response->getBody()->getContents();
            var_dump('$body');
            var_dump($body);
        } catch(\Throwable $e) {
            # 在这里干一些你需要干的事情,例如发送短信预警,发送邮件等等
            var_dump('--------------1-----------------');
            $errorCode= $e->getCode();
            $errorMessage = $e->getMessage();
            return json(['code'=>$errorCode,'msg'=>$errorMessage]);
        }
    }

    public function httpTest2()
    {
        $params          = Request::post();
        var_dump($params);
        sleep(5);
        return json(['status'=>200]);
    }

 

标签:body,dump,后处理,json,timeout,var,超时,GuzzleHttp
From: https://www.cnblogs.com/G921123/p/17814845.html

相关文章

  • Android Studio 下载Gradle 超时解决方案
    错误提示1、卡在Gradle:Downloadhttps://services.gradle.org/distributions/gradle-3.2-all.zip不动。2、提示Error:Connectiontimedout:connect。  解决方案:1、手动下载gradle.zip文件打开项目里gradle\wrapper\gradle-wrapper.properties这个文件,找到类似于下面的这一......
  • TCP协议:超时重传、流量控制、keep-alive和端口号,你真的了解吗?
    引言在之前的讲解中,我们已经介绍了TCP协议的一些面试内容,相信大家对于TCP也有了一些新的了解。今天,我们将继续深入探讨TCP的超时重传、流量控制、TCP的keepalive机制以及端口号等相关信息。这些内容对于理解TCP协议的工作原理和实际应用非常重要,希望可以加深大家对TCP协议的理解......
  • QSerialPort waitForReadyRead有数据却超时问题
    工作中用到Qt串口通讯,使用方法很简单,网上很多都使用的是异步(信号槽)方式,这里记录一下同步方式调用waitForReadyRead阻塞后,明明发送数据却还是返回超时问题。这里说的是以ASCII形式发送,也就是常见的ABCD字符十六进制形式发送waitForReadyRead会立即响应,目前还没查到具体原因。......
  • 记一次生产数据库连接超时问题排查
    背景SpringBoot2.0.8+ Hikari+ Oracle 历史项目,很久没维护了,生产上正常运行两年有余,双活架构,突然有一天其中一台后端服务器数据库连接池报错:SQLError:0,SQLState:08006SQLError:17002,SQLState:08006JDBCConnectionException:UnabletoacquireJDBCConnection初步排查......
  • 【MME编写入门】后处理模板
    1float4ClearColor={1,1,1,0};2floatClearDepth=1.0;34floatScript:STANDARDSGLOBAL<5stringScriptOutput="color";6stringScriptClass="scene";7stringScriptOrder="postprocess";8......
  • selenium4 增加超时和等待时间
    增加全局的超时和等待时间:importtimefromselenium.webdriverimportKeys,ActionChainsfromselenium.webdriver.common.byimportByfromseleniumimportwebdriverfromselenium.webdriver.chrome.serviceimportServicefromwebdriver_manager.chromeimportCh......
  • c#使用委托执行带有超时检查的方法
    namespaceTimeOutHelper{internalclassProgram{//定义一个泛型委托,用于定义带有超时检查的方法的签名publicdelegateTRTimeOutDelegate<inT,outTR>(Tparam);privatestaticvoidMain(){Dictionary<Guid,string>result;//调用Timeo......
  • c#使用委托执行带有超时检查的方法
    namespaceTimeOutHelper{internalclassProgram{//定义一个泛型委托,用于定义带有超时检查的方法的签名publicdelegateTRTimeOutDelegate<inT,outTR>(Tparam);privatestaticvoidMain(){Dictionary<Guid......
  • Python函数超时,用装饰器解决, win可以运行
        https://mp.weixin.qq.com/s/u5VGromE6iJmBBUoNaPFmw pipinstallfunc_timeout  #-*-coding:utf-8-*-importtimefromfunc_timeoutimportfunc_set_timeout@func_set_timeout(5)deftask():whileTrue:print('helloworld�......
  • 在使用 Unity 2022 打包安卓项目时,遇到 gradle 无法访问或下载超级慢最终超时出错的问
    一般表现是打包最后一步会等待超长时间,最后报错,错误信息:PickedupJAVA_TOOL_OPTIONS:-Dfile.encoding=UTF-8FAILURE:Buildfailedwithanexception.*Whatwentwrong:Aproblemoccurredconfiguringrootproject'Gradle'.>Couldnotresolveallartifactsfor......