Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP SoapClient Timeout

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.

like image 576
Shamim Hafiz - MSFT Avatar asked Aug 17 '10 08:08

Shamim Hafiz - MSFT


People also ask

How to set timeout for HTTP request in PHP?

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);

What is SoapClient in PHP?

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.

What is default_ socket_ timeout?

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.


1 Answers

Invalid answer. Please see https://stackoverflow.com/a/12119215/441739 instead.


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 the stream_context option for new SoapClient()Docs. Under the surface SoapClient uses the HTTP and SSL transports.

like image 159
Jon L. Avatar answered Oct 15 '22 15:10

Jon L.