Set Timeout SOAP Client (Zend Framework)

I am requesting a web service using SOAP for which I need to set the request timeout.

new Zend_Soap_Client(http://www.aaa.com/ws/Estimate.asmx?wsdl", array('encoding' => 'UTF-8'); 

I also tried to skip 'connection_timeout'=>100 , but this seems like an “unknown SOAP client option”. Please suggest a way to set the set timeout.

thanks

+4
source share
5 answers

The connection wait parameter is not supported, the code is present in Zend_Soap_Client, but commented

 // Not used now // case 'connection_timeout': // $this->_connection_timeout = $value; // break; 
+3
source

I found a solution to set a timeout using Zend_Framework:

If you have a SoapClient-Object like this:

 $client = new Zend_Soap_Client(http://www.aaa.com/ws/Estimate.asmx?wsdl", array('encoding' => 'UTF-8'); 

You can set a timeout for HTTP requests. The default timeout in PHP is 30 seconds. With the following code, you can, for example, set it to 1 minute.

 $context = stream_context_create( array( 'http' => array( 'timeout' => 1000 ) ) ); $client->setStreamContext($context); 

Found on downlifesroad.com

+3
source
 ini_set('default_socket_timeout',$seconds); 
+2
source

Here is a suggested solution using ZendHttpClient and Zend_Http_Client_Adapter_Curl.

  $client = new Zend_Http_Client($location); $adapter = new Zend_Http_Client_Adapter_Curl(); $client->setAdapter($adapter); $adapter->setCurlOption(CURLOPT_TIMEOUT, $this->_timeout); $client->setMethod(Zend_Http_Client::POST); $client->setHeaders('Content-Type', $version == 2 ? 'application/soap+xml' : 'text/xml'); $client->setHeaders('SOAPAction', $action); 

The idea is that you send an http request with a SOAP envelope as a string in the request.

The full gist code is here

0
source

I solved this problem using my own PHP SoapClient class ...

 $client = new SoapClient($url, array( 'connection_timeout'=>'30' )); $response = $client->wsMethod(array ('param'=>'value)); 

You can define the entire duration limit using

 ini_set('default_socket_timeout', '30'); 

Before the challenge. Works like a charm ...;)

0
source

Source: https://habr.com/ru/post/1342026/


All Articles