Commit 2dfec35e by 王召彬

上传腾讯云日志支持错误重试

parent 6a1ffe99
...@@ -50,6 +50,7 @@ class ClsLog ...@@ -50,6 +50,7 @@ class ClsLog
private static function uploadToCls($topicId, $pbData) { private static function uploadToCls($topicId, $pbData) {
$authorization = ClsSignature::create(); $authorization = ClsSignature::create();
$uri = 'http://ap-beijing.cls.myqcloud.com/structuredlog?topic_id='.$topicId; $uri = 'http://ap-beijing.cls.myqcloud.com/structuredlog?topic_id='.$topicId;
for($n = 0;$n < 3;$n++){
$res = (new Client)->post($uri, [ $res = (new Client)->post($uri, [
'headers' => [ 'headers' => [
'Host' => 'ap-beijing.cls.myqcloud.com', 'Host' => 'ap-beijing.cls.myqcloud.com',
...@@ -57,15 +58,17 @@ class ClsLog ...@@ -57,15 +58,17 @@ class ClsLog
'Content-Type' => 'application/x-protobuf', 'Content-Type' => 'application/x-protobuf',
], ],
'body'=>$pbData, 'body'=>$pbData,
'timeout' => 20, 'timeout' => 30,
]); ]);
if($res->getResponse()->getStatusCode() != 200) { if($res->getResponse()->getStatusCode() == 200) {
return true;
}
Coroutine::sleep(1);
}
$msg = '上传腾讯云日志服务失败:'.$res->getResult(); $msg = '上传腾讯云日志服务失败:'.$res->getResult();
self::writeClsErrors($msg); self::writeClsErrors($msg);
return false; return false;
} }
return true;
}
/** /**
* 腾讯日志服务上传时产生错误,这种错误需要记录在本地文件 * 腾讯日志服务上传时产生错误,这种错误需要记录在本地文件
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment