0
我使用raw blockchain api和文档说我可以每10秒做一个请求,我怎么确保我不会超过这个限制?我宁愿用php保持它的服务器端。感谢您的回应如何只使用我的最大API调用php
我使用raw blockchain api和文档说我可以每10秒做一个请求,我怎么确保我不会超过这个限制?我宁愿用php保持它的服务器端。感谢您的回应如何只使用我的最大API调用php
在每次调用API之后,都会将您的内部时间计数器添加到10秒钟以知道下一次呼叫何时会被允许。
class ApiRequest{
private $nextRequestTime = time();
private function allowRequest(){
$local_time = now();
if($local_time >= $this->nextRequestTime){
$this->nextRequestTime = ($local_time + 10);
return true;
}
return false;
}
public function doRequest($request){
if($this->allowRequest()){
// process the $request...
}
}
}
当函数返回ApiRequest::allowRequest()
你false
知道,你应该稍后处理该请求。