PHPackages                             gnikolovski/cb-rate-limiter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. gnikolovski/cb-rate-limiter

AbandonedArchivedLibrary[API Development](/categories/api)

gnikolovski/cb-rate-limiter
===========================

API rate limiter which uses Couchbase for storing data

1.0.3(5y ago)4150MITPHPPHP &gt;=5.3.0

Since Nov 19Pushed 5y ago2 watchersCompare

[ Source](https://github.com/gnikolovski/cb-rate-limiter)[ Packagist](https://packagist.org/packages/gnikolovski/cb-rate-limiter)[ Docs](https://github.com/gnikolovski/cb-rate-limiter)[ RSS](/packages/gnikolovski-cb-rate-limiter/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (5)Used By (0)

CB Rate Limiter
===============

[](#cb-rate-limiter)

Couchbase API Rate Limiter is a super simple PHP package for limiting access to your public API. It was originally created for one of my projects, and I'm using it with Slimframework, but it could be used in any of your projects.

I decided to go with Couchbase, because the rest of my application was using this database to store data. Couchbase is a super fast NoSQL database, so it is perfect for this kind of tasks.

How to install?
---------------

[](#how-to-install)

The easiest and recommended method to install CB Rate Limiter is via composer:

```
composer require gnikolovski/cb-rate-limiter

```

How to use it?
--------------

[](#how-to-use-it)

Best way to use this package is as a middleware on your routes. Put it first - before any other middleware, and if user has reached the limit you imposed, you should return http code 429 (too many requests) with appropriate headers.

This is how you could use this package with Slimframework as a middleware:

```
$app = new \Slim\App;

$app->add(function ($request, $response, $next) {
  $limiter = new CbRateLimiter($hostname, $bucket, $password);
  $limiter->whitelist($your_ip_address);
  $exceeded = $limiter->isExceeded($ip_address, $max_requests, $in_minutes);

  if (!$exceeded) {
    $resp = $next($request, $response)
      ->withHeader('X-RateLimit-Limit', 10)
      ->withHeader('X-RateLimit-Remaining', $limiter->getRemaining());
  }
  else {
    $resp = $response->withStatus(429)
      ->withHeader('X-RateLimit-Limit', 10)
      ->withHeader('X-RateLimit-Remaining', 0);
  }

  return $resp;
});

$app->get('/', function ($request, $response, $args) {
	$response->getBody()->write('Hello world');
	return $response;
});

$app->run();
```

Class is instantiated with the following three variables in the constructor:

$hostname - IP address of your Couchbase server

$bucket - name of the bucket where you will store data

$password - database password

After you create $limiter object you have to call isExceeded() method and provide the following data:

$ip\_address - IP address of user trying to access API route

$max\_requests - max requests you are willing to accept in a unit of time

$in\_minutes - unit of time

IP address of the user could be supplied using global PHP variable:

```
$_SERVER['REMOTE_ADDR']
```

or by using some package, like akrabat/rka-ip-address-middleware.

Variables $max\_requests and $in\_minutes should be integers. If you want to accept 100 requests from one IP address in 60 minutes you would write:

```
$limiter->isExceeded($_SERVER['REMOTE_ADDR'], 100, 60);
```

Requirements
------------

[](#requirements)

To use Couchbase in PHP you must install PHP SDK. To find out more visit: ()

### AUTHOR

[](#author)

Goran Nikolovski -

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~431 days

Total

4

Last Release

2168d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/593fdd394ef5c0e1e24fde560a421d21f0f89e3e0246b516e04de7c935216788?d=identicon)[gnikolovski](/maintainers/gnikolovski)

---

Top Contributors

[![gnikolovski](https://avatars.githubusercontent.com/u/16438764?v=4)](https://github.com/gnikolovski "gnikolovski (12 commits)")

---

Tags

couchbasemiddlewarenosqlphprate-limiterrate-limitingslim-framework

### Embed Badge

![Health badge](/badges/gnikolovski-cb-rate-limiter/health.svg)

```
[![Health](https://phpackages.com/badges/gnikolovski-cb-rate-limiter/health.svg)](https://phpackages.com/packages/gnikolovski-cb-rate-limiter)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
