PHP SoapClient Timeout

Shamim Hafiz picture Shamim Hafiz · Aug 17, 2010 · Viewed 83.7k times · Source

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.

Answer

Jon L. picture Jon L. · May 7, 2012

While Andrei linked to a decent solution, this one has less code yet arrives at a good solution:

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.