StackAttack is a blocking & throttling middleware for StackPHP, based heavily off of Rack::Attack for Ruby. It currently allows whitelisting and blacklisting.
{
"require": {
"league/stack-attack": "~1.0@dev"
}
}
include_once '../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use League\StackAttack\FilterCollection;
$app = new Stack\CallableHttpKernel(function (Request $request) {
return new Response('Hello World!');
});
$filters = (new FilterCollection)
->blacklist('Block dev requests.', function (Request $request) {
return strpos($request->getPathInfo(), '/dev') === 0;
});
$config = [
'blacklistedResponse' => function (Request $request) {
// A 503 response makes some bots think they had a successful DDOS
return new Response('Service Unavailable', 503);
}
];
$app = (new Stack\Builder)
->push('League\\StackAttack\\Attack', $filters, $config)
->resolve($app);
Stack\run($app);