Home >Backend Development >PHP Tutorial >Why Does My SoapClient Fail to Parse WSDL on Linux But Work on WAMP?
On a Linux master server, the SoapClient is unable to parse the WSDL from a given URL, resulting in the error: "SOAP-ERROR: Parsing WSDL: Couldn't load from - but works on WAMP". However, calling the URL directly or using curl from the command line returns the expected XML response.
Missing User Agent String:
For certain versions of PHP, the SoapClient may not send HTTP user agent information by default. This can cause issues with the web service being used.
Solution:
Explicitly set the user agent using a context stream:
$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);
Web Service Issues:
Additionally, it was discovered that the web service in question had issues with IPv6 requests without a user agent string. To verify this, try the following commands on the Linux host:
curl -A '' -6 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl curl -A 'cURL User Agent' -6 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl curl -A '' -4 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl curl -A 'cURL User Agent' -4 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
The IPv6 request without a user agent will fail, while all other requests will succeed. This suggests that the Linux host is resolving the web service's domain to its IPv6 address, and the SoapClient was not adding a user agent string by default.
The above is the detailed content of Why Does My SoapClient Fail to Parse WSDL on Linux But Work on WAMP?. For more information, please follow other related articles on the PHP Chinese website!