【发布时间】:2011-12-20 05:29:46
【问题描述】:
我的 PHP 文件中有一个检查 IP 是否被禁止的函数。由于某种原因,我的网站非常慢,问题是当我检查 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 秒。为什么?我没有离开联接或其他表。
谢谢
【问题讨论】:
标签: php mysql performance ip