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 prevent spamming users?
Extend the `DebounceNotification` class or use the `debounce()` facade method. For example, wrap your notification dispatch in `debounce(Notification::class, 10, $userId)` to delay execution for 10 seconds if triggered repeatedly by the same user or IP. Ensure your notification uses `Queueable` for async processing.
Does this package work with Laravel 10 for debouncing jobs?
Yes, but CLI (Artisan command) debouncing requires Laravel 11+. For Laravel 10, focus on jobs and notifications. Verify your cache driver supports atomic locks (Redis is recommended). Jobs must implement `ShouldQueue` to work with debouncing.
Can I use this for rate-limiting API requests or cron jobs?
This package is optimized for jobs, notifications, and CLI commands—not direct API rate-limiting. For cron jobs, debounce the job dispatching logic (e.g., wrap `YourJob::dispatch()` in `debounce()`). API rate-limiting may require middleware or dedicated packages like `spatie/rate-limiter`.
How do I configure the cache driver for debouncing?
Publish the config with `php artisan vendor:publish --tag=laravel-debounce-config` and set `driver` in `.env` (e.g., `CACHE_DRIVER=redis`). Redis is recommended for atomic locks. Avoid file cache, as it doesn’t support lock contention. Test cache persistence under load.
What happens if Redis goes down during debouncing?
Debounce locks rely on cache, so Redis downtime may cause lost locks or duplicate executions. Mitigate this by monitoring cache health and implementing a fallback (e.g., disable debouncing via `LARAVEL_DEBOUNCE_ENABLED=false` in `.env` during outages).
How can I track debounced events for analytics or debugging?
Use the built-in report tracking by enabling `report_tracking` in config. Access reports via `Debounce::report()` or monitor via Telescope. Note that reports reset on cache flushes; for persistence, log to a database or external service in `after()` hooks.
Is there a way to debounce Artisan commands in Laravel 10?
No, CLI debouncing requires Laravel 11+. In Laravel 10, create a custom command that dispatches a debounced job instead. For example, wrap `Artisan::call()` in a job that uses `debounce()` logic. Alternatively, upgrade to Laravel 11+ for native support.
How do I test debounced jobs without flaky timing issues?
Disable debouncing in tests by setting `config(['debounce.enabled' => false])` or mock the cache driver. Use `Debounce::shouldSkip()` to bypass debounce logic conditionally. Avoid relying on timing in tests; focus on verifying the debounced behavior via hooks or report tracking.
What are the performance implications of high-volume debouncing?
High concurrency may cause cache lock contention, slowing execution. Test under load with your cache driver (Redis recommended). Optimize by increasing debounce intervals or using shorter TTLs for less critical tasks. Monitor queue backlogs and cache latency.
Are there alternatives to this package for debouncing in Laravel?
For jobs/notifications, consider `spatie/laravel-activitylog` (with custom debounce logic) or `beberlei/assert` for manual lock-based debouncing. For CLI tasks, use `spatie/laravel-schedule` with custom logic. This package stands out for its Laravel-native integration (UniqueJobs, cache) and reporting features.
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai