避免客户端频繁向服务器提交表单的解决方案
使用redis
在order的model中增加函数
public function isDataLocked($key, $duration = ) {
try{
$key = "lock_" . $key;
$num = $this->redis->incr($key);
$this->redis->expire($key, $duration);
if ($num > ) {
return true;
} else {
return false;
}
} catch (Exception $e) {
$this->log->logE($e->getMessage());
return false;
}
}
在提交表单时
if ($this->model("Model_Order")->isDataLocked($key, )) { return $this->err(Common_Status::OUT_OF_FRENQUENCY, "Your operation is too frequent."); }