4

I'm requesting a webservice using SOAP for which I need to set a request timeout.

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

I have also tried passing 'connection_timeout'=>100 but it seems like "unknow SOAP client option". Please suggest a way I can set the set timeout.

Thanks

Charles
  • 50,943
  • 13
  • 104
  • 142
ravs
  • 41
  • 1
  • 2

5 Answers5

4

I found a solution to set the timeout with Zend_Framework:

If you have your SoapClient-Object like this:

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

You can set the timeout for HTTP-Requests. The default timeout in PHP is 30 seconds. With the following code you can e.g. set it to 1 minute.

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

Found on downlifesroad.com

algorhythm
  • 8,530
  • 3
  • 35
  • 47
3

Connection timeout option is not supported, the code is present in Zend_Soap_Client but commented

// Not used now
            // case 'connection_timeout':
            //     $this->_connection_timeout = $value;
            //    break;
criticus
  • 1,571
  • 8
  • 15
  • Then how will zend handles service time out issues. – ravs Mar 03 '11 at 04:30
  • @user641637 I guess you can extend Zend_Soap_Client and just redefine method setOptions(). Zend_Soap_Client uses [SoapClient](http://www.php.net/manual/en/class.soapclient.php) which supports timeout option so it should work if you define this option in your method – criticus Mar 03 '11 at 17:28
2
ini_set('default_socket_timeout',$seconds);
Daniel W.
  • 31,164
  • 13
  • 93
  • 151
chickenchilli
  • 3,358
  • 2
  • 23
  • 24
0

I solved this issue by using native PHP SoapClient class...

$client = new SoapClient($url,
            array(
                'connection_timeout'=>'30'
            ));

$response = $client->wsMethod(array
                ('param'=>'value));

You can define the whole duration limit using

ini_set('default_socket_timeout', '30');

Before calling it. Works like a charm... ;)

Ricardo Martins
  • 5,702
  • 3
  • 40
  • 59
  • 1
    `Zend_Soap_Client` internally uses `SoapClient` but fixes also some known problems around that class. So it's better to use `Zend_Soap_Client`. I posted a solution. – algorhythm Oct 23 '19 at 11:30
0

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 the SOAP envelope as string at the request.

Full gist code here

Dimitris Baltas
  • 3,115
  • 3
  • 34
  • 26