php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34657 If you get a communication problem when loading the WSDL, it fatal's
Submitted: 2005-09-27 14:32 UTC Modified: 2009-02-03 14:00 UTC
Votes:15
Avg. Score:4.5 ± 0.7
Reproduced:12 of 13 (92.3%)
Same Version:5 (41.7%)
Same OS:9 (75.0%)
From: gareth at wsys dot co dot uk Assigned: dmitry (profile)
Status: Not a bug Package: SOAP related
PHP Version: 5.1.6 OS: Windows, Linux
Private report: No CVE-ID: None
 [2005-09-27 14:32 UTC] gareth at wsys dot co dot uk
Description:
------------
When using the SOAP Client, it normally throws a catchable SoapFault exception. This helps to elegantly fail if there is a problem with a Web Service.

However, if the problem occurs when loading the WSDL, it throws a PHP Fatal Error, which cannot be caught.

This means that if you want to use a web service in a web application, you cannot handle the error (e.g. there is network congestion, or the server hosting the web service goes down).

Is this intentional, I am not sure.

If it is intentional (and I hope not given the fact that you are requesting information from a completely different server, not under your control), any chance this can be changed to throw either a SoapFault Exception, or just something that can be caught?

Reproduce code:
---------------
try {
  $sc = new SoapClient("some.wsdl", array());
} catch (Exception $e) {
  echo 'Error Caught';
}

Expected result:
----------------
Error Caught

Actual result:
--------------
Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from '{URL Removed}' 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-27 19:07 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-09-28 08:40 UTC] garadox47 at ntlworld dot com
I have tried the latest window version you provided a link to, it still throws an uncatchable fatal error.
 [2006-01-13 14:20 UTC] gareth at wsys dot co dot uk
The only solution I have come up with for this problem is to put the SOAP call into a seperate php file and then use it with exec().

This does however limit the input/output options available.
 [2006-01-14 12:08 UTC] sniper@php.net
Assigned to the maintainer. 
 [2006-09-05 12:32 UTC] dmitry@php.net
Seems this bug was already fixed in CVS HEAD, PHP_5_2 and PHP_5_1 long time ago.
 [2006-09-06 10:40 UTC] gareth at wsys dot co dot uk
Have tried on PHP version 5.1.6, still getting the following error:

Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://urlhere.com/file.wsdl'.

So I still cannot catch this error, which limits my use of SOAP as it will kill my script.
 [2006-09-08 21:50 UTC] tony2001@php.net
See also bug #38703.
 [2006-09-11 07:50 UTC] gareth at wsys dot co dot uk
I have tried to use set_error_handler(), but as you know it cannot catch fatal errors.

Does anyone else have a workaround?
 [2006-09-12 08:56 UTC] dmitry@php.net
I cannot reproduce the bug even with 5.1.4. Try "php -d log_errors=0 test.php". May be you are seeing log message and don't see "Error Caught" after it?
 [2006-09-12 09:56 UTC] gareth at wsys dot co dot uk
OK, the debug information shows that the Soap client class is now throwing an uncaught SoapFault exception (which causes the fatal error).

with a try{ } catch(SoapFault $exception) I can continue the script.

I've closed the bug.
 [2006-12-19 14:10 UTC] lsmith@php.net
I can reproduce this error with php 5.1.4 and 5.2.0 on windows. And it seems Derick was also able to reproduce it on Linux. Using the following we get 3 warnings and a fatal error:

<?php

try {
  $client = new SoapClient('http://i_dont_exist.com/some.wsdl');
} catch (SoapFault $e) {
var_dump(get_class($e));
} catch (Exception $e) {
var_dump(get_class($e));
}
var_dump($client);

It really should not do anything but throw an exception, as this is what is defined to happen for fatal errors in constructors for all extensions.
 [2006-12-21 23:32 UTC] edink@php.net
I get 3 warning + a SoapFault exception when running Lukas' test case there. The output is:

Warning: SoapClient::SoapClient(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/ek/projects/php_5_2/t on line 4

Warning: SoapClient::SoapClient(http://i_dont_exist.com/some.wsdl): failed to open stream: No such file or directory in /home/ek/projects/php_5_2/t on line 4

Warning: SoapClient::SoapClient(): I/O warning : failed to load external entity "http://i_dont_exist.com/some.wsdl" in /home/ek/projects/php_5_2/t on line 4
string(9) "SoapFault"
NULL

I think getting 3 warning and an exception for failing to load WSDL file is a bit excessive though :)

 [2007-01-15 15:53 UTC] jhendric at sierra-bravo dot com
Similar problem here with PHP 5.1.6.

try {
    $soap = new SoapClient('[...]', array('exceptions' => true)); // Note: Same results without or without exceptions => true
} catch(Exception $e) {
    var_dump($e);
}

Results in:

Warning: SoapClient::__construct([...]) [function.SoapClient---construct]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in [...]

Warning: SoapClient::__construct() [function.SoapClient---construct]: I/O warning : failed to load external entity "..." in [...]

Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from '[...]' in [...]
 [2007-02-21 17:25 UTC] lsmith@php.net
In general nothing in ext/soap should be fatal if its not within the control of the local php application. This means missing WSDL, changes to the WSDL etc. All of this needs to be catchable in some way or another (exception, returning false .. etc).

Also if an exception is thrown no warnings should be thrown for the same issue.
 [2007-03-14 23:01 UTC] craigf at togetheragency dot co dot uk
5.2.2-dev as of today (and 5.2.1) on windows is not raising a SoapFault exception regardless of if exceptions is true or false, as stated by jhendric. However, 5.2.1 on FreeBSD 4 (installed from ports) is raising an uncaught SoapFault exception as was stated by gareth . So it appears to be platform specific. In both cases, 3 additional warnings are raised.

IIS:

Warning: SoapClient::SoapClient(): php_network_getaddresses: getaddrinfo failed: No such host is known. in c:\web\test.php on line 2
Warning: SoapClient::SoapClient(h^tp://some.random.host/test.wsdl): failed to open stream: No such file or directory in c:\web\test.php on line 2
Warning: SoapClient::SoapClient(): I/O warning : failed to load external entity "h^tp://some.random.host/test.wsdl" in c:\web\test.php on line 2
Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'h^tp://some.random.host/test.wsdl' in c:\web\test.php on line 2

FreeBSD 4:

Warning: SoapClient::SoapClient(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /usr/home/www/test.php on line 2
Warning: SoapClient::SoapClient(h^tp://some.random.host/test.wsdl): failed to open stream: Unknown error: 0 in /usr/home/www/test.php on line 2
Warning: SoapClient::SoapClient(): I/O warning : failed to load external entity "h^tp://some.random.host/test.wsdl" in /usr/home/www/test.php on line 2
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'h^tp://some.random.host/test.wsdl' in /usr/home/www/test.php:2 Stack trace: #0 /usr/home/www/test.php(2): SoapClient->SoapClient('h^tp://some.ran...') #1 {main} thrown in /usr/home/www/test.php on line 2

Note: had to replace http due to spam filter.
 [2007-03-15 10:24 UTC] craigf at togetheragency dot co dot uk
Contrary to my previous post, the error is not platform specific, but rather, a conflict with the xdebug module. With xdebug enabled, the soapfault does not get raised. Using xdebug_disable() prior to the try/catch block will result in the expected result of a catch with soapfault.

Warnings still exist, but can be disabled with error_reporting() prior to the try/catch as with xdebug.
 [2007-03-26 15:41 UTC] justin dot hendrickson+pear at gmail dot com
Work around:

try {
    if(!@file_get_contents($wsdl)) {
        throw new SoapFault('Server', 'No WSDL found at ' . $wsdl);
    }
    $soap = new SoapClient($wsdl);
    // ...
} catch(SoapFault $e) {
    // ...
}
 [2007-03-30 10:10 UTC] dmitry@php.net
This is a XDEBUG issue, ext/soap may fix nothing.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 09 02:01:29 2024 UTC