Connect timeout

When the host serving the webservice is down, this can result in a connect timeout. This happens when the SoapClient tries to connect to a port at which no webserver is running. In most cases, the remote host will immediately return an error response. In some cases, however, the SoapClient will wait for a response until the socket timeout expires.

There are two settings which influence the timeout of SoapClient:

The SoapClient option connection_timeout, which is passed to the constructor, only influences the connect timeouts on requests. It does not influence the timeout which is used when retrieving the WSDL (PHP bug #48584). In contrast, the setting default_socket_timeout affects both SOAP requests and the retrieval of the WSDL. If both settings are specified, the default_socket_timeout is used when retrieving the WSDL and the connection_timeout is used for requests.

// Try connecting for one second
ini_set('default_socket_timeout', 1);
$soapClient = new SoapClient('');

The setting default_socket_timeout does not only affect the connect timeout, but also the read timeout on the WSDL.