Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Laravel Queue Rate Limit

mxl/laravel-queue-rate-limit image

Laravel Queue Rate Limit stats

Downloads
264.3K
Stars
84
Open Issues
8
Forks
16

View on GitHub →

Simple Laravel queue rate limiting

laravel-queue-rate-limit

Simple Laravel queue rate limiting

Installation

3.* versions are compatible only with Laravel 7+.

$ composer require mxl/laravel-queue-rate-limit

For Laravel 6 use 2.* versions:

$ composer require mxl/laravel-queue-rate-limit "^2.0"

For Laravel 5 use 1.* versions:

$ composer require mxl/laravel-queue-rate-limit "^1.0"

Laravel 5.5+ will use the auto-discovery feature to add MichaelLedin\LaravelQueueRateLimit\QueueServiceProvider::class to providers.

This package is not compatible with older Laravel versions.

Add rate limits to config/queue.php:

'rateLimits' => [
'mail' => [ // queue name
'allows' => 1, // 1 job
'every' => 5 // per 5 seconds
]
]

Usage

Make sure that you don't use sync connection when queueing jobs. See default property in config/queue.php.

Run queue worker:

$ php artisan queue:work --queue default,mail

Then push several jobs to default and mail queues:

Mail::queue(..., 'mail');
Mail::queue(..., 'mail');
Mail::queue(..., 'mail');
Mail::queue(..., 'default');
Mail::queue(..., 'default');

You'll see that only mail queue jobs will be rate limited while default queue jobs will run normally.

Disable logging

Extend QueueServiceProvider:

<?php
 
namespace App\Providers;
 
class QueueServiceProvider extends \MichaelLedin\LaravelQueueRateLimit\QueueServiceProvider
{
protected function registerLogger()
{
$this->app->singleton('queue.logger', function () {
return null;
});
}
}

Add it to providers array in config/app.php:

<?php
 
return [
// ...
'providers' => [
// Laravel Framework Service Providers
// ...
// Application Service Providers
// ...
App\Providers\QueueServiceProvider::class,
// ...
]
];

Maintainers

Other useful Laravel packages from the author

License

See the LICENSE file for details.

mxl photo

Chief technology officer at metapax.io

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Mxl Laravel Queue Rate Limit Related Articles

Fuse for Laravel: A Circuit Breaker Package for Queue Jobs image

Fuse for Laravel: A Circuit Breaker Package for Queue Jobs

Read article
Fair Queue Distribution with Laravel Balanced Queue image

Fair Queue Distribution with Laravel Balanced Queue

Read article
Test Job Failures Precisely with Laravel's assertFailedWith Method image

Test Job Failures Precisely with Laravel's assertFailedWith Method

Read article
Laravel 11.26 Released image

Laravel 11.26 Released

Read article
Database Job Chains for Laravel image

Database Job Chains for Laravel

Read article
Laravel 8.13 Released image

Laravel 8.13 Released

Read article
Celebian logo

Celebian

Celebian is a social media marketing agency specializing in helping their clients go viral on TikTok. Whether you're looking to reach a bigger audience or gain more Tiktok followers, likes, and views, they've got you covered.

Celebian
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud