我正在使用Zend_HTTP_Client将HTTP请求发送到服务器并获得响应。我将请求发送到的服务器是HTTPS Web服务器。当前,一个往返请求大约需要10到12秒。我了解这些开销可能是由于请求所处理的Web服务器处理缓慢所致。
是否可以像在CURL中那样跳过SSL证书检查以提高性能?如果是这样,如何设置这些参数?
我有以下代码:
try
{
$desturl ="https://1.2.3.4/api";
// Instantiate our client object
$http = new Zend_Http_Client();
// Set the URI to a POST data processor
$http->setUri($desturl);
// Set the POST Data
$http->setRawData($postdata);
//Set Config
$http->setConfig(array('persistent'=>true));
// Make the HTTP POST request and save the HTTP response
$httpResponse = $http->request('POST');
}
catch (Zend_Exception $e)
{
$httpResponse = "";
}
if($httpResponse!="")
{
$httpResponse = $httpResponse->getBody();
}
//Return the body of HTTTP Response
return $httpResponse;
如果您确信是SSL
的问题,则可以将Zend_Http_Client
配置为使用curl
,然后传递适当的curl
选项。
http://framework.zend.com/manual/en/zend.http.client.adapters.html
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => array(CURLOPT_SSL_VERIFYPEER => false),
);
$client = new Zend_Http_Client($uri, $config);
我实际上建议使用curl
适配器,因为curl
几乎具有您需要的所有选项,并且Zend确实提供了一个非常好的包装器。
至少在Magento 1中,或者如果您使用的是Varien包,则可以直接使用以下内容:
$http->setConfig(array(
// Prevent from comparing the url domain to the name on ceritifcate
'verifyhost' => 0, // default 2
// Prevent from verifying the ssl certificate
'verifypeer' => false // default true
));