How to workaround PHP’s SOAPClient bug when connecting over SSL

Today, while integrating SecPay (aka PayPoint) payment gateway with an ecommerce site I’m working on, I came across a very annoying problem with PHP’s SOAPClient implementation.

When talking to a SOAP interface the first thing you want to do is obviously connect to the endpoint:

$this->soap = new SoapClient(‘https://www.secpay.com/java-bin/services/SECCardService?wsdl’);

This looks correct and innocent, however it produces this nasty error:

SoapClient::SoapClient() [function.SoapClient-SoapClient]: SSL: fatal protocol error

Changing SOAPClient parameters doesn’t help and disabling wsdl cache in php.ini doesn’t do much either.

After googling a bit I found a couple of bug reports. It turns out PHP has issues talking to endpoints over SSL. *Sigh*.

Here’s a workaround I came up with to force PHP to connect:

$orig_error_reporting = error_reporting();
error_reporting(0);
$this->soap = new SoapClient(‘https://www.secpay.com/java-bin/services/SECCardService?wsdl’);
error_reporting($orig_error_reporting);

As you can see the idea is simple. Just turn off error reporting before instantiating soapclient and restore it afterwards.

I hope this helps some of you frustrated by this bug.

4 Responses to “How to workaround PHP’s SOAPClient bug when connecting over SSL”

  1. Sorry, don’t work for me.
    My solution was to add the follwowing packages on my debian box :
    ca-certificates libcurl3 libidn11 php5-curl

    Regards,
    Marc

  2. Darn, for a moment I thought this was working, but it turned out it just stopped telling me about the bug because of no error reporting.

    I fixed it by recompiling php with openssl support.

  3. I’m new to php, Allen, can u guide me how to recompiling php with openssl support? Thanks.

  4. Allen’s way is correct -

    Adding php_openssl should fix this issue. Not sure, but I guess if it does not work then install openssl package from http://www.openssl.org/

    In xampp package for windows, for some older XAMPP versions the php.ini file is in two places
    1. php folder
    2. apache/bin

    commandline uses php.ini in php folder
    whereas while processing http request apache/bin/php.ini is used.

    On *nix, php.ini is at one place so need to change only at one place.

    Regards,
    Aniruddha D

Leave a reply right here....