From a performance only view, which would be the best way to block 30 IP addresses?
A) .htaccess file
or
B) PHP code in the file
From a performance only view, which would be the best way to block 30 IP addresses?
A) .htaccess file
or
B) PHP code in the file
If you are administrator of your server, I would use none of those, and would ban the IPs at the firewall level -- this way, nor Apache nor Apache+PHP will have to work.
If you're not admin ; well, .htaccess
means only Apache, and no PHP to load/compile/execute ; I'm guessing Apache alone (i.e. .htaccess
) should require less resources than Apache+PHP.
Another way of seing things is maintenance : if you need to add/delete IPs addresses from that list, what would the easiest way be ?
(In that case, I would generally bet for some PHP code...)
I agree with Pascal's answer. But the PHP code is:
$banned = array('129.168.1.1');
if(in_array($_SERVER['REMOTE_ADDR'], $banned))
{
die();
}
And the .htaccess is:
order allow,deny
deny from 192.168.1.1
allow from all
Just for the record.
Why not block them at the hardware level (router, load balancer, firewall, etc)? - If its only a block of 30 and you don't need to update them often.
Hardware
or
Hardware + OS
or
Hardware + OS + Apache
or
Hardware + OS + Apache + PHP
Understanding the stacks should help indicate which will be the fastest.