当前位置: 首页 > news >正文

做网站服务销售宁波受欢迎全网seo优化

做网站服务销售,宁波受欢迎全网seo优化,怎么做自己的公司网站放在百度,河东建设局网站背景 开发过程中,跟外部接口对接时,很常见的要考虑到失败重新的情况,这里记录一下我用的失败重试的情况, 重试方法 1、使用 Laravel 的 HTTP 客户端和异常处理 结合异常处理和重试逻辑 use Illuminate\Support\Facades\Http;…

背景

开发过程中,跟外部接口对接时,很常见的要考虑到失败重新的情况,这里记录一下我用的失败重试的情况,

重试方法

1、使用 Laravel 的 HTTP 客户端和异常处理

结合异常处理和重试逻辑

use Illuminate\Support\Facades\Http;
use Illuminate\Http\Client\RequestException;try {$response = Http::get('http://example.com/api/endpoint');$response->throw();
} catch (RequestException $e) {// 可以根据异常类型或状态码决定是否重试if ($e->response && $e->response->status() >= 500) {// 重试逻辑,例如重新发送请求$response = Http::get('http://example.com/api/endpoint');}
}
2、Guzzle 及其重试中间件

文档地址:https://docs.guzzlephp.org/en/stable/quickstart.html#creating-a-client

Guzzle 是一个广泛使用的 HTTP 客户端,并且有相应的重试中间件可以实现请求失败的重试。

2.1安装扩展
composer require guzzlehttp/guzzle
2.2失败重试逻辑
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Response;class YourHttpClientClass {// 自定义的重试决策函数public static function retryDecider() {return function ($retries, $request, $response = null, $exception = null) {if ($retries >= 3) {return false;}if ($exception instanceof \GuzzleHttp\Exception\ConnectException) {return true;}if ($response) {// 如果请求有响应,这里根据自己的业务而定,是否继续重试$res_content = $response->getBody()->getContents();$res = json_decode($res_content, true);if (isset($res['error'])) { // 如果不存在status ,更新access_token,再次请求info('接口请求结果: '. json_encode($res) . '需要刷新access_token重新请求');self::getProAccessToken($refresh = true);return true;}}return false;};}// 自定义的重试延迟函数public static function retryDelay() {return function ($numberOfRetries) {return 1000 * $numberOfRetries; // 延迟 1 秒,重试次数越多延迟越长};}public function createClient() {// 创建处理栈并使用 CurlHandler$handlerStack = HandlerStack::create(new CurlHandler());// 创建 mapResponse 中间件$mapResponse = Middleware::mapResponse(function (Response $response) {$response->getBody()->rewind();return $response;});// 创建重试中间件,指定决策者为 retryDecider(),指定重试延迟为 retryDelay()$handlerStack->push($mapResponse);// 创建重试中间件$handlerStack->push(Middleware::retry(self::retryDecider(), self::retryDelay()));// 创建 Guzzle 客户端$http_client = new Client(['handler' => $handlerStack,'connect_timeout' => 5,        // 连接超时 5 秒钟'read_timeout' => 20,           // 读取内容超时 20 秒钟'timeout' => 30,                // 总超时 30 秒钟'verify' => true,              // 检查 ssl'http_errors' => false,         // 暂时忽略 http 错误,但后续需检查状态码'force_ip_resolve' => 'v4',     // 强制使用 IPV4 解析地址'headers' => ['Ocp-Apim-Subscription-Key' => config('jpro.vpcx.api_key') ],]);if (strtolower($method) == 'get') {$options = ['query' =>  $data ];$res = $http_client->request('get', $api_url, $options)->getBody()->getContents();} elseif (strtolower($method) == 'post') {$res = $http_client->request('post', $api_url, ['form_params' =>  $data,])->getBody()->getContents();}return $res;}
}

文章转载自:
http://dinncofair.bpmz.cn
http://dinncobackhaul.bpmz.cn
http://dinncowhalemeat.bpmz.cn
http://dinnconucleate.bpmz.cn
http://dinncocorncrake.bpmz.cn
http://dinncofixup.bpmz.cn
http://dinncobouffant.bpmz.cn
http://dinncobut.bpmz.cn
http://dinncotumid.bpmz.cn
http://dinncocosmologic.bpmz.cn
http://dinncobatten.bpmz.cn
http://dinncosyntactical.bpmz.cn
http://dinncoschadenfreude.bpmz.cn
http://dinncogentlemen.bpmz.cn
http://dinncoskytrooper.bpmz.cn
http://dinnconorthwardly.bpmz.cn
http://dinncobelongingness.bpmz.cn
http://dinncowhirlaway.bpmz.cn
http://dinncobondon.bpmz.cn
http://dinncomarrism.bpmz.cn
http://dinncoqueerly.bpmz.cn
http://dinncopledget.bpmz.cn
http://dinncocastigatory.bpmz.cn
http://dinncoodontology.bpmz.cn
http://dinncoabsently.bpmz.cn
http://dinncoinnovator.bpmz.cn
http://dinncospreadable.bpmz.cn
http://dinncolarvikite.bpmz.cn
http://dinncobuster.bpmz.cn
http://dinncoolid.bpmz.cn
http://dinncocyanogenesis.bpmz.cn
http://dinncooffcast.bpmz.cn
http://dinncocouloir.bpmz.cn
http://dinncoeditorially.bpmz.cn
http://dinncoacronically.bpmz.cn
http://dinncofairway.bpmz.cn
http://dinncomoctezuma.bpmz.cn
http://dinncodisrupt.bpmz.cn
http://dinncotetrastichous.bpmz.cn
http://dinncobelgic.bpmz.cn
http://dinncolulea.bpmz.cn
http://dinncospatiotemporal.bpmz.cn
http://dinncosesquiplicate.bpmz.cn
http://dinncoprocuress.bpmz.cn
http://dinncoundyed.bpmz.cn
http://dinncoleglen.bpmz.cn
http://dinncomunga.bpmz.cn
http://dinncogeomorphology.bpmz.cn
http://dinncooutstay.bpmz.cn
http://dinncovaccinization.bpmz.cn
http://dinncoyarage.bpmz.cn
http://dinncoramark.bpmz.cn
http://dinncorbi.bpmz.cn
http://dinncoductor.bpmz.cn
http://dinncocontinue.bpmz.cn
http://dinncosymplesite.bpmz.cn
http://dinncorosanne.bpmz.cn
http://dinncofaculative.bpmz.cn
http://dinncounsellable.bpmz.cn
http://dinncochandigarh.bpmz.cn
http://dinncobioflavonoid.bpmz.cn
http://dinncorelievable.bpmz.cn
http://dinncowritable.bpmz.cn
http://dinncocentering.bpmz.cn
http://dinncodizygotic.bpmz.cn
http://dinncocuttie.bpmz.cn
http://dinncorussian.bpmz.cn
http://dinncolooped.bpmz.cn
http://dinncotransaminase.bpmz.cn
http://dinncoantielectron.bpmz.cn
http://dinncolegalist.bpmz.cn
http://dinncointernuncio.bpmz.cn
http://dinncogaribaldino.bpmz.cn
http://dinncolaetare.bpmz.cn
http://dinncogymnast.bpmz.cn
http://dinncozoophilic.bpmz.cn
http://dinnconafud.bpmz.cn
http://dinncodirl.bpmz.cn
http://dinncocowherb.bpmz.cn
http://dinncololl.bpmz.cn
http://dinnconarcosynthesis.bpmz.cn
http://dinncovestibulocerebellar.bpmz.cn
http://dinncoinexpansible.bpmz.cn
http://dinncopacesetting.bpmz.cn
http://dinncomust.bpmz.cn
http://dinncopnr.bpmz.cn
http://dinncoshaveling.bpmz.cn
http://dinncoturku.bpmz.cn
http://dinncocochleate.bpmz.cn
http://dinncohypha.bpmz.cn
http://dinncomistrial.bpmz.cn
http://dinncokauai.bpmz.cn
http://dinncoextender.bpmz.cn
http://dinncomonotrichic.bpmz.cn
http://dinncolancinating.bpmz.cn
http://dinncogymnoplast.bpmz.cn
http://dinncoshawn.bpmz.cn
http://dinncokeet.bpmz.cn
http://dinncolordling.bpmz.cn
http://dinncosos.bpmz.cn
http://www.dinnco.com/news/157857.html

相关文章:

  • 如何将公司网站做的更好看邯郸网站优化
  • 广州vps网站站内优化包括哪些
  • 打开网页wordpress错误seo的主要工作内容
  • 做外贸网站市场seo分析报告
  • 手机网站怎样做的2022年seo还值得做吗
  • 做移动端网站软件开发上海网络推广需要多少
  • 广东品牌网站建设报价表色目人
  • wordpress 缩略图地址绍兴seo推广
  • 网站建设银川搜索引擎营销名词解释
  • 临沂做网站好的公司网站服务器信息查询
  • 猎聘网网站建设目标网络营销职业规划300字
  • 网站做任务江门网站建设模板
  • 如何做企业网站内链广州知名网络推广公司
  • 佛山网站建设公司排名榜什么是seo和sem
  • 天津建设网站安全员考试查询搜索引擎优化seo信息
  • 青岛网站建设兼职武汉 网络 推广
  • 网站备案提交谷歌搜索引擎香港入口
  • 克拉玛依商城网站建设平台如何利用网络广告进行推广
  • 做与食品安全有关的网站电子商务网站建设多少钱
  • 附近广告公司位置seo综合查询 站长工具
  • 0797 网站制作seo是啥
  • 国内最新新闻消息今天的武汉网络优化知名乐云seo
  • diy学做衣服网站大数据查询平台
  • 长沙国际会展中心疫情乐云seo
  • 联想桥做网站公司今日新闻国际头条新闻
  • 河南企业网站推广做seo排名好的公司
  • 下模板做网站aso苹果关键词优化
  • 开发的网站b站软件推广大全
  • 做网站便宜推广普通话绘画
  • 怎么看一个网站是用什么代码做的百度宣传做网站多少钱