public function limitGet(){
$mobile = input('mobile');
dump(count(cache(date('i'))));
if(cache(date('i')) && count(cache(date('i'))) >= 10){//每分钟限制请求10次
return submitJson(false,'','网络繁忙请重试');
}else{
if(true){//假设发送短信成功
$arr = cache(date('i')) ? cache(date('i')) : [];
$arr[] = $mobile;
cache(date('i'),$arr,60);
//cache($mobiel,短信码);
return submitJson(false,'','发送短信成功');
}else{
return submitJson(false,'','发送短信失败');
}
}demo访问如下:
ps:如果是php请求频率限流的话,把$mobile改成获取ip()即可,道理是一样的 关键是判断cache(date('i'))