Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SoapClient / Zend_Soap_Client with timeout

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..

like image 379
Daniel W. Avatar asked May 21 '14 08:05

Daniel W.


3 Answers

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

like image 125
php-dev Avatar answered Sep 19 '22 05:09

php-dev


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.

like image 38
Piotr Olaszewski Avatar answered Sep 23 '22 05:09

Piotr Olaszewski


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. :)

like image 25
doydoy44 Avatar answered Sep 22 '22 05:09

doydoy44