Jake
Jake

Reputation: 26107

Skip SSL Check in Zend_HTTP_Client

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;

Upvotes: 7

Views: 9839

Answers (2)

Malvineous
Malvineous

Reputation: 27300

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.

Upvotes: 0

Chris Henry
Chris Henry

Reputation: 12010

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.

Upvotes: 10

Related Questions