Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

PHP SoapClient fails with SOAP-ERROR: Parsing WSDL: Couldn't load from

ErrorSOAP-ERROR: Parsing WSDL: Couldn't load from 'https://example.com/service?wsdl'

Short answer

PHP throws a SoapFault when it cannot download or parse the WSDL URL. The server that runs your code, not your laptop, must reach that URL, pass its TLS check, send any login the service needs, and read a current copy. Fetch the URL from that server first, then read the exact reason in the exception message.

  • Applies to PHP 8.3, PHP 8.4, ext-soap, Linux and Windows
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Catch the exception and print its message. Everything after the first colon is the real reason. Then request the same URL from the same server with curl.

    <?php
    try {
        $client = new SoapClient('https://example.com/service?wsdl', ['trace' => true]);
    } catch (SoapFault $e) {
        echo $e->getMessage(), "\n";
    }
    // shell, on the same server:
    // curl -sS -o /dev/null -w '%{http_code}\n' 'https://example.com/service?wsdl'
  2. 2Match what you see, then jump to its fix

    1. 1curl from that server times out, cannot resolve the host, or returns a non-200 code, while a browser on your own machine worksThe server running PHP cannot reach the WSDL URLFix
    2. 2The exception message mentions SSL or certificate, and curl on the same host also complains about the certificateTLS certificate verification fails on this serverFix
    3. 3curl returns 401 for the WSDL URLThe WSDL needs HTTP authenticationFix
    4. 4The service changed or the first fetch failed, and PHP keeps using the old copy, even though the live URL is fineA stale or broken cached copy of the WSDL is usedFix
    5. 5curl with a browser-like user agent returns the WSDL, but PHP gets an error or an HTML pageThe service refuses PHP's default request headersFix

What does the error look like?

  • SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://example.com/service?wsdl'
  • a SoapFault exception thrown by new SoapClient()

Cause 1 of 5

The server running PHP cannot reach the WSDL URL

1Check

The manual says a SoapFault is thrown when the wsdl URI cannot be loaded. The usual reason is network: DNS, a firewall rule, or an allow-list at the provider that does not include this server's IP.

curl -sS -I 'https://example.com/service?wsdl'

2Fix

Open the route (outbound firewall, DNS, or the provider's IP allow-list). Set explicit timeouts so a stuck host fails quickly: connection_timeout covers connecting, and default_socket_timeout covers waiting for data.

ini_set('default_socket_timeout', '15');
$client = new SoapClient($wsdl, ['connection_timeout' => 5]);

3Verify

curl returns HTTP 200 and the client is created.

php -r '$c = new SoapClient("https://example.com/service?wsdl"); echo "ok\n";'

Confirmed by php.net

Did this fix it?

Cause 2 of 5

TLS certificate verification fails on this server

1Check

PHP verifies the peer certificate and its name by default (verify_peer and verify_peer_name default to true). A server without the right CA bundle, or a service with a private or incomplete certificate chain, fails here, while a local WAMP setup may be configured differently.

curl -vI 'https://example.com/service?wsdl' 2>&1 | grep -i -E 'certificate|ssl'

2Fix

Point PHP at a CA file that contains the issuer, through the stream_context option. Keep verification on.

$context = stream_context_create([
    'ssl' => ['cafile' => '/etc/ssl/certs/ca-certificates.crt'],
]);
$client = new SoapClient($wsdl, ['stream_context' => $context]);

3Verify

The client is created without an SSL message.

php -r '$c = new SoapClient("https://example.com/service?wsdl"); echo "ok\n";'

Confirmed by php.net

Did this fix it?

Cause 3 of 5

The WSDL needs HTTP authentication

1Check

login and password are the documented options for HTTP Basic or Digest authentication. Without them the request for the WSDL itself is refused.

curl -sS -o /dev/null -w '%{http_code}\n' 'https://example.com/service?wsdl'

2Fix

Pass the credentials in the constructor, and keep them out of source control.

$client = new SoapClient($wsdl, [
    'login'    => getenv('SOAP_USER'),
    'password' => getenv('SOAP_PASS'),
]);

3Verify

The 401 turns into a loaded client.

curl -sS -o /dev/null -w '%{http_code}\n' -u "$SOAP_USER:$SOAP_PASS" 'https://example.com/service?wsdl'

Confirmed by php.net

Did this fix it?

Cause 4 of 5

A stale or broken cached copy of the WSDL is used

1Check

soap.wsdl_cache_enabled is on by default, files go to soap.wsdl_cache_dir (default /tmp), and a cached file is used for soap.wsdl_cache_ttl seconds (default one day).

php -i | grep -i 'soap.wsdl_cache'
ls -l "$(php -r 'echo ini_get("soap.wsdl_cache_dir");')"

2Fix

Turn caching off while you debug, using the cache_wsdl option, then remove the old cached WSDL files from the cache directory.

$client = new SoapClient($wsdl, ['cache_wsdl' => WSDL_CACHE_NONE]);

3Verify

A changed WSDL shows up straight away.

php -r '$c = new SoapClient("https://example.com/service?wsdl", ["cache_wsdl" => WSDL_CACHE_NONE]); print_r($c->__getFunctions());'

Confirmed by php.net

Did this fix it?

Cause 5 of 5

The service refuses PHP's default request headers

1Check

Some providers filter by user agent. The ini setting user_agent defaults to NULL, and the stream_context option can carry a user_agent HTTP setting, so you can send an agreed value.

curl -sS -A 'MyApp/1.0' -o /dev/null -w '%{http_code}\n' 'https://example.com/service?wsdl'
curl -sS -o /dev/null -w '%{http_code}\n' 'https://example.com/service?wsdl'

2Fix

Send an agreed user agent through the HTTP context.

$context = stream_context_create(['http' => ['user_agent' => 'MyApp/1.0']]);
$client = new SoapClient($wsdl, ['stream_context' => $context]);

3Verify

The WSDL loads.

php your-script.php

Confirmed by php.net

Did this fix it?

How do I stop it coming back?

  • Catch SoapFault around the constructor and log the full message, so the real reason is not lost behind a generic page.
  • Test the WSDL URL with curl from each environment, not only from your own machine.
  • Save a copy of the WSDL in your project and load it from disk if the provider's URL is unstable.
  • Set connection_timeout and default_socket_timeout so a dead host fails in seconds.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

CodeIgniter 4 cannot write its cache files

CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/

CodeIgniter 4's file cache needs a cache directory that the web server can really write to.

2 causes, each with a fix

Back end

CodeIgniter 3 loads the model but the property is undefined

The model name you are loading is the name of a resource that is already being used: user

CodeIgniter 3 expects a model file named like its class, with the first letter capitalised, for example User_model.php holding class User_model.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.