5

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

Community
  • 1
  • 1
Daniel W.
  • 31,164
  • 13
  • 93
  • 151

3 Answers3

4

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

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
php-dev
  • 6,998
  • 4
  • 24
  • 38
  • Due to our project specifications, I must to use the `Zend_Soap_Client`. Maybe I can convince them to this solution, otherwise they have to live with a very slow cronjob. – Daniel W. May 30 '14 at 09:17
  • 1
    @DanFromGermany : `_soap` is still a `Zend_Soap_Client`! The `setSoapClient` method is a `Zend_Soap_Client` method. As you can see in the `Zend_Soap_Client` class definition, it's internally using the PHP `SoapClient` class. – php-dev May 30 '14 at 09:31
  • You are right, I just saw this after looking at the source of `\Zend\Soap\Client.php`. – Daniel W. May 30 '14 at 09:36
2

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.

Piotr Olaszewski
  • 6,017
  • 5
  • 38
  • 65
2

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

doydoy44
  • 5,720
  • 4
  • 29
  • 45