larowka/prevent-duplicate-requests
Composer 安装命令:
composer require larowka/prevent-duplicate-requests
包简介
Prevent duplicate requests middleware for Laravel applications.
README 文档
README
Middleware for Laravel that prevents duplicate requests based on user actions.
This middleware is designed to manage and prevent duplicate requests within a specified timeframe, ensuring that only unique requests are processed.
Installation
You can install the package via Composer:
composer require larowka/prevent-duplicate-requests
Usage
Laravel 11
Global Middleware
To apply middleware globally to every HTTP request in Laravel 11, you can use the withMiddleware method in your bootstrap/app.php file:
use \Larowka\PreventDuplicateRequests\Middleware\PreventDuplicateRequests; ->withMiddleware(function ($middleware) { // ... $middleware->append(PreventDuplicateRequests::class); });
Assigning Middleware to Routes
If you want to assign middleware to specific routes, use the middleware method when defining the route:
Copy code use \Larowka\PreventDuplicateRequests\Middleware\PreventDuplicateRequests; Route::get('/example', function () { // Route logic... })->middleware(PreventDuplicateRequests::class);
Middleware Aliases
You can define aliases for middleware in your bootstrap/app.php file to use shorter names for middleware classes:
use \Larowka\PreventDuplicateRequests\Middleware\PreventDuplicateRequests; ->withMiddleware(function ($middleware) { $middleware->alias([ 'preventDuplicate' => PreventDuplicateRequests::class, ]); });
Once defined, you can use the alias when assigning middleware to routes:
Route::get('/example', function () { // Route logic... })->middleware('preventDuplicate');
Laravel 10
Add the middleware to your Laravel application's HTTP kernel:
// app/Http/Kernel.php protected $routeMiddleware = [ // ... 'preventDuplicate' => \Larowka\PreventDuplicateRequests\Middleware\PreventDuplicateRequests::class, ];
Apply the middleware to your routes:
Route::middleware('preventDuplicate')->get('/example', function () { return 'Unique request handled.'; });
Or use globally:
// app/Http/Kernel.php protected $middleware = [ // ... \Larowka\PreventDuplicateRequests\Middleware\PreventDuplicateRequests::class, ];
Features
- Prevents Duplicate Requests: Blocks duplicate requests within a specified timeframe.
- Flexible Configuration: Customize the duration for which requests are cached.
- Supports Authenticated Users: Differentiates between authenticated and unauthenticated users.
- Idempotency Support: Ensures idempotent actions are enforced for user-specific operations.
Testing
Run the tests using PHPUnit:
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security issues, please email larowka@icloud.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see LICENSE for more information.
larowka/prevent-duplicate-requests 适用场景与选型建议
larowka/prevent-duplicate-requests 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.1k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 06 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「throttle」 「middleware」 「request」 「laravel」 「concurrent」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 larowka/prevent-duplicate-requests 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 larowka/prevent-duplicate-requests 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 larowka/prevent-duplicate-requests 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
A Laravel Pulse card to track users & URL's that are being throttled by your Rate Limiters
A PSR-7 compatible library for making CRUD API endpoints
hyperf cache counter rate limiter
Slim Framework 3 CSRF protection middleware utilities
Cloudflare Middleware For Guzzle
统计信息
- 总下载量: 2.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-19