我试图用PHP和mysql创建一个函数来限制每小时的请求数。我想把它保存到PHP和Mysql,我会用它们来触发其他的东西。
我一直有这方面的问题而不确定如何做到这一点。到目前为止我所拥有的是吼叫。你可以看到它并不多。怎么办呢?
$limit = 20;
$likecount = $owner->likecount = 1 + $owner->likecount;
$initialtime = $owner->initialtime= time();
$timeplushour = $owner->timeplushour = strtotime('+1 hour', $initialtime);
if($likecount <=$limit){
}
答案 0 :(得分:2)
根据docs,MySQL可以控制mysql.user
表中每个帐户(对应一行)的资源限制。
使用GRANT
语句,我们可以使用MAX_QUERIES_PER_HOUR
和MAX_UPDATES_PER_HOUR
选项指定限制,如下所示:
#create a new user
CREATE USER 'thisisme'@'localhost' IDENTIFIED BY 'thisisme';
GRANT ALL ON customer.* TO 'thisisme'@'localhost'
WITH MAX_QUERIES_PER_HOUR 20 # restrict the number of queries to 20 per hour
MAX_UPDATES_PER_HOUR 10 # restrict the number of updates to 10 per hour
MAX_CONNECTIONS_PER_HOUR 5; # restrict the number of connection to the server to 5 per hour