For the past day or so, I have been having a frustrating issue with PHP’s SoapClient object. While attempting to connect to an online web service via the SoapClient object, I kept receiving errors such as:
failed to load external entity “https://example.com/web_service/WSP_Example?xsd=xsd2”
To debug the issue, I loaded the WSDL URL in SoapUI. While using SoapUI, I was able to see that over 30 external XSD files were being imported into the WSDL file.
Although factoring off XSDs into external locations might seem like a good design idea, it seems that PHP’s SoapClient object does not like this approach at all.
At first, I thought it was a connection issue. I toyed with a number of different settings to try and get PHP’s SoapClient to play ball:
- I set the PHP script’s timeout limit to 200 seconds using the function set_time_limit.
- I changed PHP’s default_socket_timeout ini setting to 200 seconds.
- In the options array for SoapClient, I set the connection_timeout to 200.
- I modified PHP’s SOAP cache settings.
- I modified SoapClient’s SSL settings.
Unfortunately, none of the tweaks above worked.
In the end, I came across the following article, which basically states that having numerous XSDs imports can cause compatibility issues with some clients. In my case, I had to ask the owners of the web service to provide me a “flattened” version of the WSDL file. I then used a local copy of the flattened WSDL file with SoapClient.