1) In case of timeout, PHP throws a SoapFault exception with faultcode="HTTP"
and faultstring="Error Fetching http headers"
.
2) In my opinion, the best way to distinguish between a timeout error and web service issues is by looking at the faultcode
and faultstring
members of the SoapFault class.
In particular, the faultcode
element is intended for use by software to provide an algorithmic mechanism for identifying the fault.
As you can also read in a comment of the PHP manual, there is no method to read the faultcode
property, so you have to access it directly (eg. $e->faultcode
), because the getCode()
method does not work.
The SOAP 1.1 Spec defines four possible values for the faultcode
field:
- VersionMismatch: işleme taraf SOAP Zarf elemanı için geçersiz bir ad buldu
- MustUnderstand: işleme tarafın itaat anlaşılmamış ya da değil ya da SOAP Header elemana bir acil alt öğesi bir soap "1" değeri ile nitelik mustUnderstand içeriyordu
- Client: hataları İşveren sınıfı iletisi yanlış kuruldu ya da başarılı olmak için gerekli bilgileri içeren olmadığını göstermektedir. Örneğin, mesaj uygun kimlik veya ödeme bilgi eksikliği olabilir. Genel olarak mesaj değişiklik olmadan yeniden gönderilmesini olmamalıdır bir göstergesidir.
- Server: hataları sunucu sınıfı mesajı mesajın kendisi değil, mesajın işleme içeriğine doğrudan ilişkili olmayan nedenlerle işlenen olamayacağını göstermektedir. Örneğin, işleme yanıt vermedi, bir yukarı akış işlemcisi, iletişim içerebilir. Mesajı zaman içinde daha sonraki bir noktada başarılı olabilir.
In addiction to those codes, PHP uses the HTTP
code for identifying the errors happening at the protocol level (eg.: socket errors); for example, if you search for add_soap_fault
in the ext/soap/php_http.c source code you can see when some of these kind of faults are generated.
By searching for the add_soap_fault
and soap_server_fault
functions in the PHP SOAP extension source files, I've built the following list of PHP SoapFault
exceptions:
HTTP
----
Unable to parse URL
Unknown protocol. Only http and https are allowed.
SSL support is not available in this build
Could not connect to host
Failed Sending HTTP SOAP request
Failed to create stream??
Error Fetching http headers
Error Fetching http body: No Content-Length: connection closed or chunked data
Redirection limit reached: aborting
Didn't recieve an xml document
Unknown Content-Encoding
Can't uncompress compressed response
Error build soap request
VersionMismatch
---------------
Wrong Version
Client
------
A SOAP 1.2 envelope can contain only Header and Body
A SOAP Body element cannot have non Namespace qualified attributes
A SOAP Envelope element cannot have non Namespace qualified attributes
A SOAP Header element cannot have non Namespace qualified attributes
Bad Request
Body must be present in a SOAP envelope
Can't find response data
DTD are not supported by SOAP
encodingStyle cannot be specified on the Body
encodingStyle cannot be specified on the Envelope
encodingStyle cannot be specified on the Header
Error cannot find parameter
Error could not find "location" property
Error finding "uri" property
looks like we got "Body" with several functions call
looks like we got "Body" without function call
looks like we got no XML document
looks like we got XML without "Envelope" element
Missing parameter
mustUnderstand value is not boolean
SoapClient::__doRequest() failed
SoapClient::__doRequest() returned non string value
Unknown Data Encoding Style
Unknown Error
DataEncodingUnknown
MustUnderstand
--------------
Header not understood
Server
------
Couldn't find WSDL
DTD are not supported by SOAP
Unknown SOAP version
WSDL generation is not supported yet
3) zaman aşımı durumu taklit etmek için, aşağıdaki kodu deneyin:
soapclient.php
<?php
ini_set('default_socket_timeout', 10);
$client = new SoapClient(null,
array(
'location' => "http://localhost/soapserver.php",
'uri' => "http://localhost/soapserver.php",
'trace' => 1
)
);
try {
echo $return = $client->__soapCall("add",array(41, 51));
} catch (SoapFault $e) {
echo "<pre>SoapFault: ".print_r($e, true)."</pre>\n";
//echo "<pre>faultcode: '".$e->faultcode."'</pre>";
//echo "<pre>faultstring: '".$e->getMessage()."'</pre>";
}
?>
soapserver.php
<?php
function add($a, $b) {
return $a + $b;
}
sleep(20);
$soap = new SoapServer(null, array('uri' => 'http://localhost/soapserver.php'));
$soap->addFunction("add");
$soap->handle();
?>
Notice the sleep
call in the SoapServer.php
script with a time (20) longest than the time (10) specified for the default_socket_timeout
parameter in the SoapClient.php
script.
If you want to simulate a service unavailability, you could for example change the location
protocol from http
to https
in the soapclient.php
script, assuming that your web server is not configured for SSL; by doing this, PHP should throw a "Could not connect to host" SoapFault.