gpt4 book ai didi

PHP 设置 Mysql 每小时限制

转载 作者:行者123 更新时间:2023-11-29 07:50:08 25 4
gpt4 key购买 nike

我正在尝试使用 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){

}

最佳答案

根据docs ,MySQL 提供对 mysql.user 表中每个帐户(对应于一行)的资源限制的控制。

使用GRANT语句中,我们可以使用 MAX_QUERIES_PER_HOURMAX_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

关于PHP 设置 Mysql 每小时限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26707707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com