class SoapClientX extends SoapClient {
private $timeout;
function __construct($wdsl, $options = array()) {
// 考虑到不和原函数冲突.
if (isset ( $options ['timeout'] )) {
$this->timeout = intval ( $options ['timeout'] );
} else {
$this->timeout = 10;
}
parent::__construct ( $wdsl, $options );
}
public function __doRequest($request, $location, $action, $version, $one_way = false) {
ini_set ( 'default_socket_timeout', $this->timeout );
try {
// 当超时返回空时,表示非正常报文返回,出现"Error Fetching http headers"异常
$response = parent::__doRequest ( $request, $location, $action, $version, $one_way );
} catch ( Exception $e ) {
if (stristr ( $e->getMessage (), "Error Fetching http headers" )) {
throw new SoapFault ( 'timeout', "请求超时" );
}
}
if (! $response) {
throw new SoapFault ( 'timeout', "请求超时" );
}
return ($response);
}
}