furkankufrevi/laravel-slow-query-detector
Composer 安装命令:
composer require furkankufrevi/laravel-slow-query-detector
包简介
Detect slow queries and N+1 problems in your Laravel app. Logs warnings with query details, execution time, and origin.
README 文档
README
A lightweight Laravel package that detects slow database queries and N+1 problems, logging them with execution time and origin trace.
Installation
composer require furkankufrevi/laravel-slow-query-detector
The service provider is auto-discovered. To publish the config:
php artisan vendor:publish --tag=slow-query-detector-config
Setup
Add the middleware to your routes or groups:
// bootstrap/app.php (Laravel 11+) ->withMiddleware(function (Middleware $middleware) { $middleware->append(\SlowQueryDetector\Middleware\SlowQueryMiddleware::class); }) // app/Http/Kernel.php (Laravel 10) protected $middleware = [ \SlowQueryDetector\Middleware\SlowQueryMiddleware::class, ];
Configuration
Set via .env or publish the config file:
SLOW_QUERY_DETECTOR_ENABLED=true SLOW_QUERY_THRESHOLD=100 SLOW_QUERY_LOG_CHANNEL=
| Option | Default | Description |
|---|---|---|
enabled |
true |
Enable/disable the detector |
threshold |
100 |
Slow query threshold in milliseconds |
detect_n_plus_one |
true |
Enable N+1 duplicate query detection |
duplicate_threshold |
3 |
Min repeated queries to trigger N+1 warning |
log_channel |
null |
Log channel (null = default) |
include_trace |
true |
Include origin stack trace in logs |
trace_depth |
5 |
Max stack frames to capture |
Log Output
Slow query:
[Slow Query] GET /users | 250.00ms | select * from users where active = 1 | Origin: UserController.php:42
N+1 detection:
[N+1 Detected] GET /posts | Query repeated 15x: select * from comments where post_id = '3'
Summary:
[Query Summary] GET /posts | 18 queries | 320.50ms total
License
MIT
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-16