处理金柚超时请求

This commit is contained in:
“wanyongkang”
2024-07-02 18:41:04 +08:00
parent 4ad116651b
commit e1959e1225

View File

@@ -43,7 +43,21 @@ class Jinyoujingtai{
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5); // 设置CURL超时时间
$response = curl_exec($ch); $response = curl_exec($ch);
// 检查是否因为超时而返回FALSE
if ($response === false) {
$error = curl_error($ch);
if (strpos($error, 'Operation timed out') !== false || curl_errno($ch) === CURLE_OPERATION_TIMEDOUT) {
// 这里处理超时异常
echo json_encode(["code"=> 200,"data"=>[]]);
} else {
// 这里处理其他CURL错误
echo json_encode(["code"=> 200,"data"=>[]]);
}
die;
}
curl_close($ch); curl_close($ch);
return $response; return $response;