定制 furkankufrevi/laravel-slow-query-detector 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固