PHPackages                             cellard/throttle - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. cellard/throttle

AbandonedLibrary[Utility &amp; Helpers](/categories/utility)

cellard/throttle
================

Laravel Throttle Service may throttle any events, not only requests

1.0.4(5y ago)022MITPHPPHP &gt;=7.0

Since May 22Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Cellard/throttle)[ Packagist](https://packagist.org/packages/cellard/throttle)[ RSS](/packages/cellard-throttle/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (3)Dependencies (1)Versions (5)Used By (0)

Laravel Throttle Service
========================

[](#laravel-throttle-service)

Laravel built-in throttling allows to rate limit access to routes. But what about other processes, e.g. sending sms?

For example, you may need to limit amount of sms, user allowed to receive from your service. Or maybe you need to limit number of comments, user allowed to write in some time period.

This service can throttle any event you need:

```
try {
    throttle('sms')
        ->subject('+70001234567')
        ->try();

    // Your code to send SMS here

} catch (\Cellard\Throttle\ThrottlingException $exception) {
    // No, You Don't
}
```

Installation
------------

[](#installation)

```
composer require Cellard/throttle

```

Register Service Provider in `config/app.php` file.

```
'providers' => [
    /**
     * Third Party Service Providers...
     */
    Cellard\Throttle\ThrottleServiceProvider::class
],
```

Publish the package config file and migrations to your application. Run these commands inside your terminal.

```
php artisan vendor:publish --provider="Cellard\Throttle\ThrottleServiceProvider"

```

And also run migrations.

```
php artisan migrate

```

Setup
-----

[](#setup)

Set up your throttle service.

```
class ThrottleSms extends Cellard\Throttle\ThrottleService
{
    public function rules()
    {
        return [
            '1:60', // one sms per minute
            '3:300', // 3 sms per 5 minutes
            '5:86400', // maximum 5 sms every day
        ];
    }
}
```

Exactly the same, but with helpers.

```
class ThrottleSms extends Cellard\Throttle\ThrottleService
{
    public function rules()
    {
        return [
            $this->everyMinute(),
            $this->everyFiveMinutes(3),
            $this->daily(5)
        ];
    }
}
```

Then register your service in `config/throttle.php`.

```
return [
    'events' => [
        'sms' => ThrottleSms::class
    ]
];
```

### Error messages

[](#error-messages)

By default error messages looks like `Next :event after :interval`

```
Next sms after 23 hours 32 minutes 13 seconds

```

You may define custom error messages.

```
class ThrottleSms extends Cellard\Throttle\ThrottleService
{
    public function rules()
    {
        return [
            '1:60' => 'You may send only one SMS per minute',
            '3:300' => 'You may send no more than three SMS in five minutes'
        ];
    }
}
```

Placeholders:

- limit — number of events (defined in rule)
- seconds — number of seconds (defined in rule)
- event — name of service (defined in config file)
- interval - `CarbonInterval` object (time left to the next allowed hit)

Usage
-----

[](#usage)

```
$throttle = Throttle::event('sms')->subject('+70001234567');

if ($throttle->allow()) {

    // Your code to send SMS here

    // Do not forget to register an event
    $throttle->hit();

} else {

    // Show error message
    $throttle->error();

    // Show the time, next sms is allowed
    $throttle->next();

}
```

Or in try-catch style

```
try {

    Throttle::event('sms')
        ->subject('+70001234567')
        ->try();

    // Your code to send SMS here

} catch (\Cellard\Throttle\ThrottlingException $exception) {

    // Show error message
    $exception->getMessage();

    // Show the time, next sms is allowed
    $exception->getNext();
}
```

Also you may use helper function.

```
throttle('sms')
    ->subject('+70001234567')
    ->try();
```

What is `subject`?
------------------

[](#what-is-subject)

`Subject` is a scope.

You may check availability without subject.

```
Throttle::event('sms')->try();
```

It means that service will check limitations without reference to the exact phone number.

Subject means that service will check limitations per phone.

```
Throttle::event('sms')->subject('+70001234567')->try();
```

Pick up your room before you go out
-----------------------------------

[](#pick-up-your-room-before-you-go-out)

Throttle Service stores records in its table, and you may want to clear it.

```
php artisan throttle:clean

```

Will remove obsolete records.

You may schedule it to run once a day or week...

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 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 ~24 days

Total

4

Last Release

2112d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce23eaf7ae48d79d2b07efc83ff7cecb2664f428bd531b167b90169423f1453d?d=identicon)[Cellard](/maintainers/Cellard)

---

Top Contributors

[![Cellard](https://avatars.githubusercontent.com/u/1220316?v=4)](https://github.com/Cellard "Cellard (10 commits)")

---

Tags

laravelsmsthrottlelimitation

### Embed Badge

![Health badge](/badges/cellard-throttle/health.svg)

```
[![Health](https://phpackages.com/badges/cellard-throttle/health.svg)](https://phpackages.com/packages/cellard-throttle)
```

###  Alternatives

[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[forxer/laravel-gravatar

A library providing easy gravatar integration in a Laravel project.

4235.6k](/packages/forxer-laravel-gravatar)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)

PHPackages © 2026

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