【问题标题】:Skip SSL Check in Zend_HTTP_Client在 Zend_HTTP_Client 中跳过 SSL 检查
【发布时间】:2011-03-23 00:37:57
【问题描述】:

我正在使用 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;

【问题讨论】:

  • 您猜到性能问题可能是什么?为什么不能确定呢?

标签: php zend-framework ssl curl https


【解决方案1】:

如果您确信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 确实提供了一个非常好的包装器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-28
    • 2011-02-14
    • 1970-01-01
    • 2018-10-03
    • 2019-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多