I'm using the following method trying to set a timeout to the SoapClient. $this->_soap is a Zend_Soap_Client which wraps a  SoapClient object.
Sometimes the API call I'm doing takes > 60 seconds. I'm trying to set a 10 seconds timeout but this doesn't work.
1. Using stream_context_create:
public function setTimeout($timeout)
{
    $this->_soap->setStreamContext(stream_context_create(array(
        'http' => array(
            'timeout' => intval($timeout)
        )
    )));
}
2. I tried as Part of the constructor, like in this answer (PHP SoapClient Timeout) which is working with SoapClient object:
    $this->_soap     = new \Zend_Soap_Client($this->_wsdl, array(
        'soap_version'       => SOAP_1_1,
        'connection_timeout' => intval($timeout)
    ));
But it is not working because Zend doesn't support this option and throws Unknown SOAP client option.
3. I tried default_socket_timeout:
ini_set("default_socket_timeout", intval($timeout));
None of those did work:
 API calls times (seconds):     min 0.3012      max 23.0334     avg 2.5005
What I could try now is, to append to the public function setOptions($options) in "\Zend\Soap\Client.php" with a timeout, but I don't want to touch the Zend core files..
I doubt that dynamically setting the timeout option is possible.
However, can you try this method?
$this->_soap->setSoapClient(
    new SoapClient(
        $this->_wsdl, 
        array(
            'soap_version'       => SOAP_1_1,
            'connection_timeout' => intval($timeout)
        )
    )
);
Hope it helps. Thanks
In documentation: SoapClient:
The connection_timeout option defines a timeout in seconds for the connection to the SOAP service. This option does not define a timeout for services with slow responses. To limit the time to wait for calls to finish the default_socket_timeout setting is available.
About your trial 2, there is the issue ZF-9125: connection_timeout option not supported in Zend_Soap_Client.
There is an extend Zend_Soap_Client as solution. 
Maybe it will help you. :)
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