Php “如何修复卷曲错误”;SSL连接超时“;仅在第一次调用脚本时?

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

我在Windows服务器上使用cURL和PHP时遇到了一个奇怪的问题。我有一个非常基本的代码:

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连接超时”

对脚本的后续调用将输出所需的结果,但是,如果在再次调用脚本之前等待几分钟,超时问题将再次发生

因此,重现“错误”的步骤如下:

  • 调用脚本->SSL连接超时
  • 再次调用脚本->工作正常
  • 再次调用脚本->工作正常
  • 调用脚本n次以上->效果良好
  • 等10分钟
  • 调用脚本->SSL连接超时
  • 再次调用脚本n次->工作正常
  • 如果我调用任何其他脚本,响应都是立即的,即使在一段时间不活动之后也是如此,因此这种行为只有在涉及cURL时才会发生

    PHP-5.2.17 CURL-libcurl/7.16.0openssl/0.9.8qzlib/1.2.3 服务器运行Windows 2012和IIS 8,最新升级,在FastCGI上运行PHP

    有人知道我如何解决这个问题吗


    谢谢。

    尝试使用此处提供的ca-bundle.crt捆绑包

    上传文件

    curl_setopt($ch,CURLOPT_CAINFO,“路径”)

    参考:

    希望这有帮助