[英]PHP SOAP - Expanding __doRequest
I am trying to expand PHP's \\SoapClient to include timeout and retry capabilities...I have tried to implement both of the following two scripts without any success 我正在尝试扩展PHP的\\ SoapClient以包括超时和重试功能...我试图实现以下两个脚本都没有成功
https://github.com/ideaconnect/idct-soap-client/blob/master/src/client.php https://github.com/ideaconnect/idct-soap-client/blob/master/src/client.php
https://gist.github.com/RobThree/2490351 https://gist.github.com/RobThree/2490351
The strange thing is, a completely default soap request works perfectly for me. 奇怪的是,完全默认的soap请求对我来说非常合适。 The following script also works perfectly for me...
以下脚本也非常适合我...
class SoapTest extends \SoapClient {
public function __construct($wsdl, $options) {
parent::__construct($wsdl,$options);
}
public function __doRequest ($request, $location, $action, $version, $one_way = null) {
$response = parent::__doRequest($request, $location, $action, $version, $one_way);
return $response;
}
}
However when I start trying to implement my own __doRequest code I can't get it working no matter the hundred variations I have tried. 但是,当我开始尝试实现自己的__doRequest代码时,无论尝试了多少种变化,我都无法使它正常工作。 Below is one of the snippets I have tried, does anyone know the default options/lines I need to use to make it behave natively?
以下是我尝试过的代码段之一,有人知道我需要使用默认选项/行来使其自然显示吗?
$curl = curl_init($location);
$options = array(
CURLOPT_VERBOSE => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $request,
CURLOPT_HEADER => false,
CURLOPT_NOSIGNAL => false,
CURLOPT_HTTPHEADER => array(sprintf('Content-Type: %s', $version == 2 ? 'application/soap+xml' : 'text/xml'), sprintf('SOAPAction: %s', $action)),
CURLOPT_SSL_VERIFYPEER => $this->sslverifypeer
);
if ($this->timeout>0) {
if (defined('CURLOPT_TIMEOUT_MS')) { //Timeout in MS supported?
$options[CURLOPT_TIMEOUT_MS] = $this->timeout;
} else { //Round(up) to second precision
$options[CURLOPT_TIMEOUT] = ceil($this->timeout/1000);
}
}
if ($this->connecttimeout>0) {
if (defined('CURLOPT_CONNECTTIMEOUT_MS')) { //ConnectTimeout in MS supported?
$options[CURLOPT_CONNECTTIMEOUT_MS] = $this->connecttimeout;
} else { //Round(up) to second precision
$options[CURLOPT_CONNECTTIMEOUT] = ceil($this->connecttimeout/1000);
}
}
if (curl_setopt_array($curl, $options) === false)
throw new Exception('Failed setting CURL options');
$response = curl_exec($curl);
Thanks for any help you can provide. 感谢您的任何帮助,您可以提供。
I would avoid to re-invent the wheel. 我会避免重新发明轮子。 The SoapClient already handles the timeout (see the connection_timeout option of the constructor in the doc .
SoapClient已经处理了超时(请参阅doc中的构造函数的connection_timeout选项。
Then you can just implement the retries doing something like 然后,您可以执行重试,例如
public function __doRequest ($request, $location, $action, $version, $one_way = null) {
try {
$response = parent::__doRequest($request, $location, $action, $version, $one_way);
} catch (SoapFault $e) {
// handle the retry
}
return $response;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.