StackPHP Middleware based on Rack::Attack
Latest commit 6c9f2fa Nov 1, 2013 @dongilbert dongilbert add link to stackphp


StackAttack is a blocking & throttling middleware for StackPHP, based heavily off of Rack::Attack for Ruby. It currently allows whitelisting and blacklisting.

Install Via Composer

    "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)