Simple rate-limit firewall.
PHP 5.5+ and APCu extension or phpredis extension 2.2+ are required.
Add these lines to your composer.json
.
"require": {
"ariarijp/cassowary": "dev-master"
}
<?php
require_once __DIR__.'/vendor/autoload.php';
define('CASSOWARY_THRESHOLD', 20);
Cassowary\Adapter\RedisAdapter::init([
'host' => 'localhost',
'port' => 6379,
'prefix' => 'cassowary_',
'index' => 9,
'ttl' => 10,
]);
Cassowary\Cassowary::kick(CASSOWARY_THRESHOLD, $_SERVER['REMOTE_ADDR'], Cassowary\Adapter\RedisAdapter::class, function($host) {
error_log($host. ' added to blacklist.');
}, function($host, $count) {
header('HTTP/1.1 403 Forbidden');
exit;
});
<?php
require_once __DIR__.'/vendor/autoload.php';
define('CASSOWARY_THRESHOLD', 20);
Cassowary\Adapter\ApcuAdapter::init([
'prefix' => 'cassowary_',
'ttl' => 10,
]);
Cassowary\Cassowary::kick(CASSOWARY_THRESHOLD, $_SERVER['REMOTE_ADDR'], Cassowary\Adapter\ApcuAdapter::class, function($host) {
error_log($host. ' added to blacklist.');
}, function($host, $count) {
header('HTTP/1.1 403 Forbidden');
exit;
});
MIT