SOAPFault When Switching PHP Versions

I’m working on an update to my PHP Web Services book and with PHP 7 likely to release before the book even makes it into print, I’m testing all my example code across PHP 5.6 and PHP 7 … which today gave me a weird problem with a very, very simple SOAP example.

<?php

$client = new SoapClient('http://api.radioreference.com/soap2/?wsdl&v=latest');

$countries = $client->getCountryList();
print_r($countries);

This example works fine with PHP 5 but when I ran it with PHP 7 (after realising I needed to recompile with --enable-soap), I got this error:

Fatal error: Uncaught SoapFault exception: [Client] Function ("getCountryList") is not a valid method for this service ...

Hmm. So I complained about it on IRC and someone else tried it on 7 and said it worked fine (thanks @akrabat) but that it didn’t work under 5.6 for him.

I can only speculate about what changed between versions and it’s probably a good thing, whatever it is, but it seems like once the WSDL is cached locally from one version of PHP, it makes no sense with the other version. To fix it, disable the WSDL cache:

ini_set("soap.wsdl_cache_enabled", "0");

This worked for me, and I am not sure how I would have found a strange SOAP fault between PHP versions other than by a lucky help from someone else, so it’s here in the hope that it saves time for someone else too!

12 thoughts on “SOAPFault When Switching PHP Versions

  1. Wouldn’t it be better to change the cache directories to different locations based on the versions? This way it would still cache (which is a considerable performance improvement).

  2. Thanks for sharing this. I manage an app that consumes a SOAP service and it often takes several minutes to load the WSDL, so I have to use the WSDL cache.

    I have a scheduled task which refreshes the cache outside of peak hours so that it’s always current. The scheduled task uses “ini_get(“soap.wsdl_cache_dir”)” and then scandir() and unlink() to delete the cached files. You could use something similar with the above version-switching problem, i.e. do a manual refresh of the cache after a version-switch rather than disabling cache completely.

    As I type I thought of something possibly fancier – perhaps you could extend SoapClient and in the constructor check the PHP version against a user-cached version – if it doesn’t match (i.e. the PHP version has changed since the last call to the SoapClient), it could do a cache refresh before invoking the parent class.

    Please excuse me if I am talking out of my backside, I am not used to sharing code concepts with such luminaries :-)

  3. I’d also rather change the cache-dir using the soap.wsdl_cache_dir parameter in the php.ini instead of disabling caching at all. But instead of reading the parameter and deleting everything on version switching I’d just set the parameter to a sensible default like [code]soap.wsdl_cache_dir = /tmp/php[php-version][/code]

  4. Thanks a lot, saved my day really!
    Also could be worth noting that if you create your initial SoapClient with WSDL_CACHE_BOTH parameter and want to clear this WSDL cache, be sure to clear both cache on disk AND in-memory.

  5. Thank you, i’ve created a separated wsdl_cache_dir and used ini_set(“soap.wsdl_cache_dir”, $wsdl_cache_dir); to set it.

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.