PHP SoapClient: Failed to load external entity.

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 the following error:

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 as though 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 work:

  1. I set the PHP script’s timeout limit to 200 seconds using the function set_time_limit.
  2. I changed PHP’s default_socket_timeout ini setting to 200 seconds.
  3. In the options array for SoapClient, I set the connection_timeout to 200.
  4. I modified PHP’s SOAP cache settings.
  5. 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 XSD imports can cause compatibility issues with some clients.

In my case, I had to ask the owners of the web service to provide me with a “flattened” version of the WSDL file. I then used a local copy of the flattened WSDL file with SoapClient.