Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Debounce

Laravel Debounce Laravel Package

zackaj/laravel-debounce

Debounce Laravel jobs, notifications, and (Laravel 11+) Artisan commands to prevent spamming users and queues. Uses unique job locks + cache to delay execution until activity stops. Tracks each occurrence with request metadata (IP, user) and provides reporting.

View on GitHub
Deep Wiki
Context7

Debounce jobs ,notifications and artisan commands.

Frequently asked questions about Laravel Debounce
How do I debounce a Laravel notification to avoid spamming users?
Use the `Debounce::notification()` method with your notification class and a delay (e.g., `Debounce::notification(new FileUploaded($file), 10)`). The package will ensure only one notification executes per debounce window, even if triggered multiple times.
Does this package work with Laravel 10 or older versions?
Yes, but CLI debouncing (Artisan commands) requires Laravel 11+. For older versions, focus on debouncing jobs and notifications. Check the [README](https://github.com/codeartbtw/laravel-debounce) for version-specific setup.
What cache driver should I use for atomic locks?
Redis is recommended for performance and reliability. Database caching works but may introduce latency. Ensure your cache driver supports atomic operations (e.g., `cache()->lock()`). Avoid file-based caching for production.
How do I generate unique keys for debouncing?
Use dynamic keys tied to the user or request context, like `user()->id` or `request()->ip()`. Static keys (e.g., `'send_notification'`) will debounce all occurrences globally. The package defaults to `user_id + request_ip` for notifications.
Can I test debounce behavior without affecting production?
Yes, disable debouncing entirely in testing by setting `LARAVEL_DEBOUNCE_ENABLED=false` in your `.env`. This bypasses all debounce logic while keeping your code unchanged. Useful for CI/CD pipelines or local testing.
What happens if the cache is cleared while a job is debounced?
Debounce state is lost, potentially causing duplicate executions. Mitigate this by using a persistent cache (e.g., Redis) or implementing a fallback (e.g., database-backed locks). The package doesn’t auto-recover, so plan for cache resilience.
How do I debounce an Artisan command in Laravel 11+?
Wrap your command logic in `Debounce::command()` with a delay, e.g., `Debounce::command(fn() => Artisan::call('queue:work'), 30)`. This works for CLI tasks like `php artisan your:command` and prevents rapid re-execution.
Does this package integrate with Laravel Telescope?
Yes, enable reporting via `config(['laravel-debounce.reporting' => true])` to log debounce occurrences (IP, user, timestamp). These appear in Telescope under the `laravel-debounce` tab, helping debug or audit debounced tasks.
What are the performance implications of tracking occurrences?
Minimal overhead—each occurrence adds a cache write. For high-frequency tasks (e.g., >1000/min), disable reporting (`'reporting' => false`) or use a faster cache driver like Redis. Benchmark under load if critical.
Are there alternatives if I’m not using Laravel’s queue system?
For non-queue systems, use Redis’s `SETNX` or a custom lock service. The debounce logic relies on Laravel’s `UniqueJobs` middleware, so alternatives require rebuilding atomic locks. The package’s core (cache + delays) is adaptable to other PHP frameworks.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata