SOAPFault When Switching PHP Versions
<?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:
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!
Thanks for sharing.
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).
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 :-)
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]
Thanks for sharing. Was my issue too.
Thanks for sharing. Had the same issue.
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.
Thanks for sharing. Had the same issue. Was about to go back to 5.5 for this issue.
Thank you, just hit this issue when upgrading to PHP 7, clearing the wsdl cache did the trick :)
Thank you, i’ve created a separated wsdl_cache_dir and used ini_set(“soap.wsdl_cache_dir”, $wsdl_cache_dir); to set it.
Thank you very much for this!
Clearing the PHP WSDL cache (/tmp/wsdl* by default) worked for us! Thanks!