设置超时 SOAP 客户端 (Zend Framework)

发布于 2024-10-19 23:43:02 字数 292 浏览 7 评论 0原文

我正在使用 SOAP 请求 Web 服务,我需要为其设置请求超时。

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

我也尝试过传递 'connection_timeout'=>100 但它看起来像“未知 SOAP 客户端选项”。请建议我可以设置超时的方法。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

茶花眉 2024-10-26 23:43:02

我找到了一个使用 Zend_Framework 设置超时的解决方案:

如果您有这样的 SoapClient-Object:

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

您可以设置 HTTP 请求的超时。 PHP 中的默认超时时间是 30 秒。使用以下代码,您可以将其设置为 1 分钟。

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

发现于 downlifesroad.com

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

相对绾红妆 2024-10-26 23:43:02

不支持连接超时选项,代码存在于 Zend_Soap_Client 中但已注释

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

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;
伪装你 2024-10-26 23:43:02
ini_set('default_socket_timeout',$seconds);
ini_set('default_socket_timeout',$seconds);
森林很绿却致人迷途 2024-10-26 23:43:02

这是使用 ZendHttpClient 和 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);

这个想法是您发送一个 http 请求,其中 SOAP 信封作为请求中的字符串。

完整要点代码此处

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

一枫情书 2024-10-26 23:43:02

我通过使用本机 PHP SoapClient 类解决了这个问题

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

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

...可以使用调用之前定义整个持续时间限制

ini_set('default_socket_timeout', '30');


就像一个魅力......;)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文