我试图用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){
}发布于 2014-11-03 05:20:19
根据文档,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 hourhttps://stackoverflow.com/questions/26707707
复制相似问题