2014-11-03 69 views
0

我試圖用PHP和mysql創建一個函數來限制每小時的請求數。我想保留它到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

這個問題是相當模糊。我們可以看到你的所有代碼嗎? 「我到目前爲止...」非常不完整。 – EvilZebra 2014-11-03 04:27:37

回答

2

按照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