In this case, the user encounters a SOAP error while trying to consume a WSDL from a web service. The error specifically states that the SOAP client is unable to load the WSDL from the provided URL.
The key to resolving this issue lies in the different behavior of SOAP clients on various PHP versions. Some versions of PHP omit sending HTTP user agent information, leading to problems when attempting to access the web service.
Here's a solution to set the user agent explicitly using a context stream:
try { $opts = array( 'http' => array( 'user_agent' => 'PHPSoapClient' ) ); $context = stream_context_create($opts); $wsdlUrl = 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl'; $soapClientOptions = array( 'stream_context' => $context, 'cache_wsdl' => WSDL_CACHE_NONE ); $client = new SoapClient($wsdlUrl, $soapClientOptions); $checkVatParameters = array( 'countryCode' => 'DK', 'vatNumber' => '47458714' ); $result = $client->checkVat($checkVatParameters); print_r($result); } catch(Exception $e) { echo $e->getMessage(); }
It's worth noting that the issue could also be attributed to problems with the web service itself. By testing the URL using curl with and without a user agent, it was discovered that IPv6 requests without a user agent string failed while IPv4 requests with or without a user agent string succeeded.
This observation suggests a compatibility issue between the web service and the specific configuration of the user's Linux host.
The above is the detailed content of Why Does My SOAP Client Fail to Load a WSDL on Some PHP Versions?. For more information, please follow other related articles on the PHP Chinese website!