ariarijp/cassowary

Simple rate-limit firewall.

Installs: 21

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 0

Open Issues: 0

Type:firewall

dev-master 2016-05-11 14:10 UTC

This package is auto-updated.

Last update: 2024-10-23 12:10:32 UTC


README

Simple rate-limit firewall.

Requirements

PHP 5.5+ and APCu extension or phpredis extension 2.2+ are required.

Installation

Add these lines to your composer.json.

"require": {
    "ariarijp/cassowary": "dev-master"
}

Usage

Using RedisAdapter

<?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;
});

Using ApcuAdapter

<?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;
});

License

MIT

Author

ariarijp