PHP's SoapClient times out after twice the time of default_socket_timeout when fetching WSDL

2.5k Views Asked by At

I'm using PHP's built-in SoapClient, and it needs to time out after 5 seconds. Therefore I'm using ini_set("default_socket_timeout", 5);. However, when fetching the WSDL it times out after 10 seconds instead. If I change the default socket timeout to i.e. 1 second it times out after 2 and so on. The actual soap calls time out after 5 seconds as expected though.

Is this a bug in PHP, expected behaviour or is there some additional setting I need to change? Using PHP 5.6.28.

Thanks!

1

There are 1 best solutions below

4
On

There is an additional timeout setting that you will want to change: connection_timeout which is passed to the SoapClient in the $options array parameter. This timeout controls how long the SoapClient waits (in seconds) to connect to the Soap service, which is what you are looking for.

Usage:

$soapclient = new SoapClient($uri, array('connection_timeout' => 5));

Once connected, "default_socket_timeout" comes into play and controls how long the SoapClient waits for a response.