在 Zend_HTTP_Client 中跳过 SSL 检查

发布于 2024-09-12 01:57:56 字数 963 浏览 6 评论 0原文

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

I am using Zend_HTTP_Client to send HTTP requests to a server and get response back. The server which I am sending the requests to is an HTTPS web server. Currently, one round trip request takes around 10-12 seconds. I understand the overhead might be because of the slow processing of the web server to which the requests go.

Is it possible to skip SSL certificate checks like we do in CURL to speed up the performance? If so, how to set those parameters?

I have the following code:

    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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

揪着可爱 2024-09-19 01:57:57

我只需要在处理遗留代码库时解决这个问题,并且能够像这样解决这个问题:

        $client = new Zend_Http_Client();

        // Disable SSL hostname verification.
        $client->getAdapter()->setStreamContext([
            'ssl' => [
                'verify_peer_name' => false,
            ]
        ]);

您可以与 verify_peer_name 一起设置的所有其他 SSL 选项是 在 PHP 手册中列出

I just had to address this while working on a legacy codebase, and I was able to work around the problem like this:

        $client = new Zend_Http_Client();

        // Disable SSL hostname verification.
        $client->getAdapter()->setStreamContext([
            'ssl' => [
                'verify_peer_name' => false,
            ]
        ]);

All the other SSL options you can set along with verify_peer_name are listed in the PHP manual.

断肠人 2024-09-19 01:57:56

如果您确信 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 几乎拥有您需要的所有选项,并且 < em>Zend 确实提供了一个非常好的包装器。

If you're confident SSL is the issue, then you can configure Zend_Http_Client to use curl, and then pass in the appropriate curl options.

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);

I actually recommend using the curl adapter, just because curl has pretty much every option you'll ever need, and Zend does provide a really nice wrapper.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文