qdenka/laravel-query-doctor 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

qdenka/laravel-query-doctor

Composer 安装命令:

composer require qdenka/laravel-query-doctor

包简介

Detect N+1 queries, missing indexes, and slow queries in your Laravel app before they reach production.

README 文档

README

CI Latest Version License

Detect N+1 queries, missing indexes, and slow queries in your Laravel app before they reach production.

  • Catches 5 types of problems: N+1, duplicate queries, slow queries, missing indexes, unnecessary SELECT *.
  • Works in dev and CI: Web dashboard for browsing, CLI commands for reporting, exit codes for CI pipelines.
  • Zero config to start: Install, open /query-doctor, see results.

Requirements

  • PHP 8.2+
  • Laravel 10, 11, or 12
  • SQLite PHP extension (included in most PHP installations)

Installation

composer require --dev qdenka/laravel-query-doctor
php artisan vendor:publish --tag=query-doctor-config

That's it. The package auto-discovers and starts capturing queries.

Quick Start

  1. Install the package (see above).
  2. Browse your app — make some requests, trigger some pages.
  3. Open /query-doctor in your browser.

Or generate a report from the command line:

php artisan doctor:report

CLI Commands

Command Description
php artisan doctor:report Show detected issues
php artisan doctor:report --format=json Output as JSON
php artisan doctor:report --format=md --output=report.md Save markdown report to file
php artisan doctor:baseline Snapshot current issues as baseline
php artisan doctor:baseline --clear Remove the baseline
php artisan doctor:ci-report --fail-on=high CI mode: exit 1 if high+ severity issues exist
php artisan doctor:ci-report --baseline CI mode: exclude baselined issues

CI Integration

# .github/workflows/ci.yml
- name: Run tests
  run: vendor/bin/phpunit

- name: Check query performance
  run: php artisan doctor:ci-report --fail-on=high --output=report.md

- name: Upload report
  if: always()
  uses: actions/upload-artifact@v4
  with:
    name: query-doctor-report
    path: report.md

Configuration

Publish and edit the config file:

php artisan vendor:publish --tag=query-doctor-config

Key options:

// config/query-doctor.php
return [
    'enabled' => env('QUERY_DOCTOR_ENABLED', true),
    'allowed_environments' => ['local', 'staging'],

    'analyzers' => [
        'n_plus_one' => ['min_repetitions' => 5],
        'slow' => ['threshold_ms' => 100],
        'duplicate' => ['min_count' => 3],
    ],
];

See docs/CONFIGURATION.md for the full reference.

Dashboard

The web dashboard is available at /query-doctor (only in allowed environments).

It shows:

  • Issues grouped by severity
  • Slow queries with timing details
  • N+1 candidates with query counts
  • Filters by period, route, severity, and type

Security

Query bindings are sanitized before storage:

  • Column-based masking: Bindings for columns like password, token, api_key are replaced with [MASKED].
  • Pattern-based masking: Strings matching email, phone, or SSN patterns are masked regardless of column.
  • Hash-only storage: Bindings are stored as SHA-256 hashes for duplicate detection, not raw values.

You can add your own columns and patterns in the config:

'masking' => [
    'columns' => ['password', 'secret', 'token', 'date_of_birth'],
    'value_patterns' => ['/^[A-Z]{2}\d{6}$/'],  // passport numbers
],

How It Works

  1. The package hooks into Laravel's DB::listen() to capture every SQL query.
  2. Queries are fingerprinted (normalized) to group structurally identical queries.
  3. Five analyzers run against captured queries to detect problems.
  4. Results are stored in a dedicated SQLite file (separate from your app's database).
  5. You view results via the dashboard, CLI, or exported reports.

See docs/ARCHITECTURE.md for the full architecture overview.

Extending

Add custom analyzers:

use QDenka\QueryDoctor\Domain\Contracts\AnalyzerInterface;

final class MyCustomAnalyzer implements AnalyzerInterface
{
    public function analyze(array $events): array { /* ... */ }
    public function type(): IssueType { /* ... */ }
}

See docs/EXTENSION_API.md for details on custom analyzers, reporters, and event hooks.

Contributing

See CONTRIBUTING.md.

License

MIT. See LICENSE.

qdenka/laravel-query-doctor 适用场景与选型建议

qdenka/laravel-query-doctor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「performance」 「sql」 「query」 「profiling」 「laravel」 「diagnostics」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 qdenka/laravel-query-doctor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 qdenka/laravel-query-doctor 我们能提供哪些服务?
定制开发 / 二次开发

基于 qdenka/laravel-query-doctor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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