Php “如何修复卷曲错误”;SSL连接超时“;仅在第一次调用脚本时?
我在Windows服务器上使用cURL和PHP时遇到了一个奇怪的问题。我有一个非常基本的代码:Php “如何修复卷曲错误”;SSL连接超时“;仅在第一次调用脚本时?,php,windows,curl,Php,Windows,Curl,我在Windows服务器上使用cURL和PHP时遇到了一个奇怪的问题。我有一个非常基本的代码: private function curlConnection($method, $url, $timeout, $charset, array $data = null) { if (strtoupper($method) === 'POST') { $postFields = ($data ? htt
private function curlConnection($method, $url, $timeout, $charset, array $data = null)
{
if (strtoupper($method) === 'POST') {
$postFields = ($data ? http_build_query($data, '', '&') : "");
$contentLength = "Content-length: " . strlen($postFields);
$methodOptions = array(
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postFields,
);
} else {
$contentLength = null;
$methodOptions = array(
CURLOPT_HTTPGET => true
);
}
$options = array(
CURLOPT_HTTPHEADER => array(
"Content-Type: application/x-www-form-urlencoded; charset=" . $charset,
$contentLength,
'lib-description: php:' . PagSeguroLibrary::getVersion(),
'language-engine-description: php:' . PagSeguroLibrary::getPHPVersion()
),
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_CONNECTTIMEOUT => $timeout
);
$options = ($options + $methodOptions);
$curl = curl_init();
curl_setopt_array($curl, $options);
$resp = curl_exec($curl);
$info = curl_getinfo($curl);
$error = curl_errno($curl);
$errorMessage = curl_error($curl);
curl_close($curl);
$this->setStatus((int) $info['http_code']);
$this->setResponse((String) $resp);
if ($error) {
throw new Exception("CURL can't connect: $errorMessage");
} else {
return true;
}
}
问题是,第一次调用此脚本时,响应总是这样:string(22)“SSL连接超时”
对脚本的后续调用将输出所需的结果,但是,如果在再次调用脚本之前等待几分钟,超时问题将再次发生
因此,重现“错误”的步骤如下:
谢谢。尝试使用此处提供的ca-bundle.crt捆绑包 上传文件 curl_setopt($ch,CURLOPT_CAINFO,“路径”) 参考: 希望这有帮助