连接到第三方时需要重试。只需使用反射编写重试代理。上面的代码:classRetry{/***@varobjectproxyobject*/private$__proxy;/***@varint重试一次*/private$__retry_times=1;/***@varint延迟一秒*/private$__delay_time=1000000;/***@param$name*@param$args*@returnmixed*@throwsException*/publicfunction__call($name,$args){if(!method_exists($this->get_proxy(),$name)){thrownewException('找不到方法。');}$次=0;$reflection=newReflectionClass($this->get_proxy());$method=$reflection->getMethod($name);if(!$method->isPublic()||$method->isAbstract()){thrownewException('方法不是公共的或抽象的。');}while($times<$this->get_retry_times()){try{$res=$method->invokeArgs($this->get_proxy(),$args);返回$资源;}catch(Exception$e){$times++;如果($times>=$this->__retry_times){throw$e;}usleep($this->get_delay_microseconds());}}}publicfunctionset_proxy($real_subject){$this->__proxy=$real_subject;}publicfunctionget_proxy(){return$this->__proxy;}publicfunctionset_retry_times($retry_times){$this->__retry_times=$retry_times;}publicfunctionget_retry_times(){return$this->__retry_times;}publicfunctionset_delay_microseconds($delay_time){$this->__delay_time=$delay_time;}publicfunctionget_delay_microseconds(){return$this->__delay_time;}}
