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
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:
- Database Queries: Every SQL query with execution time
- HTTP Calls: External API requests via Laravel's HTTP client
- Memory Usage: Peak memory consumption per request
- 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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zeeshantariq/laravel-api-profiler 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
g4 application profiler package
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
A Symfony bundle for chameleon-system/sanitycheck
WordPress mu-plugin to remove jQuery Migrate from the list of jQuery dependencies and to allow jQuery to enqueue before </body> instead of in the <head>.
Create link to static resources with cache-breaking segment based on md5 of the file
SoftWax Health Check Bundle for Symfony framework
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 41
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-11