我正在使用一些Web服务SoapClient.我正在寻找一种机制,可以帮助我在Web服务脱机或关闭时向用户显示一些错误.
因为在向用户显示任何错误之前我必须等待一段时间(15秒).我加入connection_timeout的SoapClient这个样子,超时.
$this->client = new SoapClient($clienturl,array('trace' => 1,
'exceptions'=> 1,
'connection_timeout'=> 15)); //$clienturl is webservice url
Run Code Online (Sandbox Code Playgroud)
同样在页面的顶部,我添加了这一行,
ini_set("default_socket_timeout", 15); // 15 seconds
Run Code Online (Sandbox Code Playgroud)
在特定的超时间隔后,我会变SOAP-ERROR得像这样,
SOAP-ERROR: Parsing WSDL: Couldn't load from $clienturl
Run Code Online (Sandbox Code Playgroud)
所以我正在寻找一个错误处理程序来处理这些错误处理程序,SOAP-ERROR以便以人类可读的格式向用户显示"服务器关闭,一段时间后再试".或者有没有办法处理超时错误?
你可以把它放在try/catch中
try {
$time_start = microtime(true);
$this->client = new SoapClient($clienturl,array('trace' => 1,
'exceptions'=> 1,
'connection_timeout'=> 15
));
} catch (Exception $e) {
$time_request = (microtime(true)-$time_start);
if(ini_get('default_socket_timeout') < $time_request) {
//Timeout error!
} else {
//other error
//$error = $e->getMessage();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15006 次 |
| 最近记录: |