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

3 Answers 3

4
+100

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

Sign up to request clarification or add additional context in comments.

3 Comments

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.
@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.
You are right, I just saw this after looking at the source of \Zend\Soap\Client.php.
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.

Comments

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

1 Comment

Interesting! Thx for the link

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.