SOAP Error: Parsing WSDL on Production Server
When attempting to utilize a SoapClient to parse a WSDL from a remote URL, a SOAP-ERROR was encountered on a production server. The local WAMP server handled the operation successfully, but the issue persisted on the production server.
Error Message
The specific error message received was:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl' : failed to load external entity "http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl"/taxation_customs/vies/checkVatService.wsdl"
Investigation
Upon further investigation, it was discovered that the error resulted from the SoapClient's inability to parse the WSDL when attempting to load it from the URL. This occurred despite the WSDL being accessible via a direct call using curl from the command line.
Solution
The issue was resolved by setting the user agent explicitly within the SoapClient using a context stream:
$soapClientOptions = array( 'stream_context' => $context, 'cache_wsdl' => WSDL_CACHE_NONE ); $client = new SoapClient($wsdlUrl, $soapClientOptions);
This approach ensured that the necessary HTTP user agent information was included in the request, allowing the SoapClient to successfully parse the WSDL from the remote URL.
Additional Insights
Further analysis revealed that the issue could also be attributed to specific settings on the production server. HTTP requests over IPv6 with a missing HTTP user agent string seemed to trigger the error. By forcing IPv4 or explicitly specifying a user agent string, the request was able to succeed without encountering the SOAP error.
The above is the detailed content of Why does my SoapClient fail to parse a WSDL on the production server but works on my local server?. For more information, please follow other related articles on the PHP Chinese website!