7

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

Posted November 12th, 2009 in PHP by Damian

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.

7 Responses so far.

  1. Marc says:

    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. Allen says:

    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.

    • Leo says:

      You just saved my day thank you so much!

    • Charles says:

      My install of PHP has openSSL enabled. I’m getting the same issue…I know the service endpoint works over port 80. Trying it over SSL (self-signed cert) but no go. I suspect this has something to do with it being a self-signed cert….

  3. Ms.Peace says:

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

  4. Aniruddha says:

    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 https://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