该脚本在带有nusoap库的php 4上运行
require_once('nusoap/lib/nusoap.php');
ini_set("soap.wsdl_cache_enabled", "0");
$client = new soapclient("some-url",true);
$err = $client->getError();
if ($err)
{
header("Location: error-page");
exit();
}
我的问题是:如果检测到错误,是否可以等待1-2秒(类似睡眠(2);)然后尝试重新启用肥皂连接?并且为了将来参考......我怎样才能获得所有可能的错误并为它们构建案例?例如,对于某些错误,请等待重新初始化连接,对于其他一些错误,请记录db的原因,其余的只是重定向到一般错误页面。
答案 0 :(得分:1)
你知道如何编程,对吗?只需将代码放入循环:
$retries = 3; // how many times to retry the connection
$sleep = 2; // number of seconds to sleep in-between retries
$i = 1;
while (TRUE) {
$client = new soapclient("some-url",true);
if ( ! $client->getError()) {
break; // break out of the loop on success
} elseif ($i === $retries) {
header("Location: error-page");
exit();
}
sleep($sleep);
++$i;
}