我在我的PHP文件中检查IP是否被禁止的功能。出于某种原因,我的网站速度很慢,问题是我检查IP是否被禁止。mysql查询速度慢--IP查找(禁止与否)
(我删除检查代码和我的网站是再次快速)
这里是我的代码:
// index.php - everything redirects to this file in the .htaccess
<?php
include('config.php');
if(isIpBanned($_SERVER['REMOTE_ADDR'])) {
die('access denied');
}
// rest of the code
这里是我的功能
// config.php
<?php
function isIpBanned($db, $ip) { // $db is declared correctly
$goodIP = $db->getRecord("SELECT is_banned FROM security.ip WHERE ip = '$ip'"); // this function works and return 1 or 0
return (bool)$goodIP;
}
这个查询大约需要2秒运行3秒。为什么?我没有离开连接或其他表格。
谢谢
1.1.1.1不是一个整数,你怎么能有INT作为数据类型? –
@Gino查找'ip2long'和'long2ip' PHP函数或INET_ATON()和INET_NTOA()MySQL函数 – CAFxX
INT比查找的CHAR(20)快吗? –