2010-07-30 35 views
3

我正在使用Zend_HTTP_Client向服務器發送HTTP請求並獲取響應。我發送請求的服務器是HTTPS Web服務器。目前,一個往返請求需要大約10-12秒。我瞭解,開銷可能是因爲請求發送到的Web服務器處理緩慢。跳過SSL簽入Zend_HTTP_Client

是否可以像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; 
+0

您猜測性能問題可能是什麼?爲什麼不確定? – 2010-07-30 00:17:34

回答

6

如果你確信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公司確實提供了一個非常好的包裝。