对curl增加日志

This commit is contained in:
cloud 2024-12-23 12:34:44 +08:00
parent 8740c22d39
commit 91bde9fa4b
1 changed files with 15 additions and 1 deletions

View File

@ -1088,9 +1088,23 @@ class curls
$data = curl_exec($curl); $data = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE); //http响应码 $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); //http响应码
$errno = curl_errno($curl); //错误码 $errno = curl_errno($curl); //错误码
$error = curl_error($curl); // 获取cURL错误信息
curl_close($curl); curl_close($curl);
$this->data = empty($errno) ? $data : $this->appcore->codemsg(4011, "{$code}-{$errno}")->coderes(false); // $this->data = empty($errno) ? $data : $this->appcore->codemsg(4011, "{$code}-{$errno}")->coderes(false);
if ($errno){
// 如果发生错误,记录错误信息到日志文件
$logMessage = "[" . date('Y-m-d H:i:s') . "] ERROR: HTTP Code: $code, cURL Error No: $errno, Error: $error\n";
file_put_contents(PATH_APP_FILE.'config/curl_error.log', $logMessage, FILE_APPEND); // 将日志追加到文件中
$this->data = $this->appcore->codemsg(4011, "{$code}-{$errno}")->coderes(false);
}else{
$this->data = $data;
}
} else { } else {
// 如果发生错误,记录错误信息到日志文件
$logMessage = "[" . date('Y-m-d H:i:s') . "] ERROR: cURL extension is not available.\n";
file_put_contents(PATH_APP_FILE.'config/curl_error_b.log', $logMessage, FILE_APPEND); // 将日志追加到文件中
$this->data = $this->appcore->codemsg(4000)->coderes(false); $this->data = $this->appcore->codemsg(4000)->coderes(false);
} }
return $this; return $this;