zeeshantariq/laravel-api-profiler 问题修复 & 功能扩展

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

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

zeeshantariq/laravel-api-profiler

Composer 安装命令:

composer require zeeshantariq/laravel-api-profiler

包简介

Production-grade performance observability for Laravel APIs - track database queries, external API calls, memory usage, and execution time with interactive dashboard

README 文档

README

Latest Version Total Downloads Laravel PHP License Status

Production‑grade performance observability for Laravel APIs

Laravel API Profiler helps you understand why your APIs are slow by tracking database queries, external API calls, memory usage, and execution time — all in one powerful dashboard.

✨ Features

  • ⏱️ Request & route performance
  • 🗄️ SQL query timing + N+1 detection
  • 🌐 External HTTP call tracking
  • 🧠 Bottleneck detection (DB, HTTP, Memory, App)
  • 📊 Interactive dashboard with charts
  • 🚨 Slow request & anomaly alerts
  • 🧭 Route based analytics

🧠 Why not Telescope?

Feature Telescope Laravel API Profiler
Production safe
N+1 detection
Bottleneck detection
API focused
Performance charts

🛠 Installation

composer require zeeshantariq/laravel-api-profiler
php artisan migrate

🔧 Usage

Basic Setup

Add the middleware to your API routes:

use ZeeshanTariq\LaravelApiProfiler\Middleware\ApiProfilerMiddleware;

Route::middleware(['api', ApiProfilerMiddleware::class])->group(function () {
    // Your API routes
});

Or use the middleware alias:

Route::middleware(['api', 'api-profiler'])->group(function () {
    // Your API routes
});

Access the Dashboard

Visit the dashboard at:

http://your-app.test/api-profiler/dashboard

Configuration

Publish the config file:

php artisan vendor:publish --tag=config --provider="ZeeshanTariq\LaravelApiProfiler\LaravelApiProfilerServiceProvider"

Available configuration options in config/api-profiler.php:

return [
    // Enable/disable the profiler
    'enabled' => env('API_PROFILER_ENABLED', true),
    
    // Slow request threshold in milliseconds
    'slow_request_threshold_ms' => 500,
    
    // High memory threshold in bytes (default: 128MB)
    'high_memory_bytes' => 128 * 1024 * 1024,
    
    // N+1 query detection threshold
    'n_plus_one_threshold' => 5,
    
    // Number of samples for baseline calculation
    'baseline_sample_size' => 50,
    
    // Middleware for dashboard routes
    'middleware' => ['web', 'auth'],
];

Environment Variables

Add to your .env file:

API_PROFILER_ENABLED=true

📊 Dashboard Features

Main Dashboard (/api-profiler/dashboard)

  • Overview Stats: Total requests, slow requests, active alerts
  • Request Breakdown Chart: Visual timeline showing DB, HTTP, Middleware, and Controller time
  • Route Performance Chart: Average duration per route over time

Requests Page (/api-profiler/requests)

  • List of all profiled requests
  • Search and filter functionality
  • Click any request to see detailed analysis

Request Detail Page

For each request, you can see:

  • Performance Metrics: Duration, memory usage, query count, HTTP calls
  • Bottleneck Detection: Identifies if the issue is Database, HTTP, Memory, or Application
  • N+1 Detection: Highlights repeated queries with suggestions
  • Timeline Tab: Visual breakdown of request execution
  • Queries Tab: All SQL queries with execution times
  • HTTP Calls Tab: External API calls with durations

Routes Page (/api-profiler/routes)

  • Performance metrics grouped by route
  • Average duration, slow request count, error count
  • Health status indicators

Alerts Page (/api-profiler/alerts)

  • Slow requests (>500ms by default)
  • High memory usage alerts
  • N+1 query detection alerts
  • Click to view detailed request analysis

🧪 Example

Calling:

GET /api/v1/clients/15/assets

The profiler will show:

  • Total Duration: 980ms
  • Database Time: 760ms (77% of total)
  • SQL Queries: 32 queries executed
  • N+1 Detected: Query executed 15+ times
  • Bottleneck: Database
  • Alert: Slow Request (>500ms)

This helps you identify that the issue is database-related and likely due to N+1 queries.

🔍 How It Works

Automatic Tracking

The profiler automatically tracks:

  1. Database Queries: Every SQL query with execution time
  2. HTTP Calls: External API requests via Laravel's HTTP client
  3. Memory Usage: Peak memory consumption per request
  4. Execution Time: Total request duration broken down by component

Bottleneck Detection

The profiler identifies the main performance bottleneck:

  • Database: If DB time > 200ms
  • External API: If HTTP time > 300ms
  • Memory: If memory usage > 128MB
  • Application: Otherwise

N+1 Query Detection

Automatically detects when the same query is executed multiple times (threshold: 5+ times), suggesting potential N+1 problems that can be solved with eager loading.

Performance impact

The profiler is designed to be lightweight:

  • Data is stored asynchronously
  • Minimal overhead on requests
  • Can be disabled in production if needed via config

📸 Screenshots

(Add screenshots of your dashboard here)

📝 Requirements

  • PHP >= 8.2
  • Laravel >= 11.0
  • MySQL/PostgreSQL/SQLite

🧭 Roadmap

  • Real‑time WebSocket dashboard
  • Slack & Email alerts
  • Per‑route baselines
  • Anomaly detection
  • Team dashboards
  • Export reports
  • API endpoints for programmatic access

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This package is open-sourced software licensed under the MIT license.

👤 Author

Zeeshan Tariq
Laravel Architect & AI Engineer

📄 License

MIT

zeeshantariq/laravel-api-profiler 适用场景与选型建议

zeeshantariq/laravel-api-profiler 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 5, 最近一次更新时间为 2026 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 zeeshantariq/laravel-api-profiler 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 0
  • Forks: 1
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-11