Is there anyway for a SoapClient Request to time out and throw an exception. As of now, I get PHP Server response timeout, in my case 60 seconds. Basically what I want is, if there isn't any reply from the Web Service within certain time, an exception would be thrown and I could catch it. The 60 seconds warning is not what I want.
Setting the default timeout Before doing anything else, you should decrease the default timeout early in your code to a value between 5 and 10 seconds: <? php ini_set("default_socket_timeout", 10);
Description ¶ This is a low level API function that is used to make a SOAP call. Usually, in WSDL mode, SOAP functions can be called as methods of the SoapClient object. This method is useful in non-WSDL mode when soapaction is unknown, uri differs from the default or when sending and/or receiving SOAP Headers.
default_socket_timeout int. Default timeout (in seconds) for socket based streams. Specifying a negative value means an infinite timeout. from string. The email address to be used on unauthenticated FTP connections and as the value of From header for HTTP connections, when using the ftp and http wrappers, respectively.
While Andrei linked to a decent solution, this one has less code yet arrives at a good solution:
* Handling Timeouts with PHP5 SoapClient Extension (by Antonio Ramirez; 02 Feb 2010)
Example code:
//
// setting a connection timeout (fifteen seconds on the example)
//
$client = new SoapClient($wsdl, array("connection_timeout" => 15));
And there is also the stream context, if you need more fine-grained HTTP control. See thestream_context
option fornew SoapClient()
Docs. Under the surfaceSoapClient
uses the HTTP and SSL transports.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With