oussemakh1/laravel-query-optimizer
Composer 安装命令:
composer require oussemakh1/laravel-query-optimizer
包简介
Enhance Laravel query performance with logging, analysis, and AI-powered insights.
README 文档
README
The Laravel Query Optimizer is a package designed to monitor, analyze, and optimize database query performance in Laravel applications. It provides tools to log query execution details, analyze performance metrics, and suggest improvements through a user-friendly dashboard and API endpoints. The package leverages Doctrine DBAL for advanced query analysis and integrates seamlessly with Laravel's service provider architecture.
Demos
Here are some demo images showcasing the Laravel Query Optimizer package:
![]() |
![]() |
Features
- Query Logging: Records SQL queries, their bindings, execution time, and timestamps.
- Performance Dashboard: Visualizes query statistics, execution times, and query distribution.
- API Endpoints: Retrieve query metrics and get detailed query explanations using an external AI service (Gemini API).
- Console Commands: View and clear query statistics from the command line.
- Customizable Configuration: Configure log paths, API keys, and other settings.
- Doctrine DBAL Integration: Offers advanced database schema analysis for query optimization.
Requirements
- PHP >= 8.0
- Laravel >= 8.x
- Doctrine DBAL
- Supported database drivers: MySQL, PostgreSQL, SQLite, SQL Server
Installation
-
Install via Composer:
composer require oussemakh1/laravel-query-optimizer
-
Publish Configuration:
php artisan vendor:publish --tag=config
This will copy the configuration file to
config/queryoptimizer.php. -
(Optional) Publish Views:
php artisan vendor:publish --tag=queryoptimizer-views
This will copy dashboard views to
resources/views/vendor/queryoptimizer. -
(Optional) Publish Assets:
php artisan vendor:publish --tag=assets
This will copy JavaScript assets to
resources/js/queryoptimizer. -
Configure Gemini API Key (for query explanations) in
config/queryoptimizer.php:return [ 'log_path' => storage_path('logs/query_optimizer.log'), 'gemini_api_key' => env('GEMINI_API_KEY', ''), ];
Then add
GEMINI_API_KEYto your.envfile.
Configuration
Edit config/queryoptimizer.php to customize:
log_path: Path for query logs (default:storage/logs/query_optimizer.log).gemini_api_key: API key for Gemini AI service.- Other settings as needed.
Usage
Dashboard
Visit /query-optimizer/dashboard to see:
- Total queries executed
- Total & average execution time
- Slowest query details
- Execution time charts
- Query distribution over time
- Detailed logs with filters (all, fast, medium, slow)
API Endpoints
Under /api/query-optimizer:
- GET
/metrics– Returns performance statistics. - POST
/explain– Analyzes an SQL query and returns an explanation (requires Gemini API key).
Example:
curl -X POST http://your-app.com/api/query-optimizer/explain \ -H "Content-Type: application/json" \ -d '{"sql": "SELECT * FROM users WHERE created_at > NOW()"}'
Console Commands
-
Show Stats:
php artisan query-optimizer:stats
-
Clear Stats:
php artisan query-optimizer:clear-stats
How It Works
- Service Provider: Registers
QueryAnalyzer, sets up routes, views, and commands. - Query Logging:
QueryLoggerclass logs details to the configured file. - Analysis:
QueryAnalyzertracks queries, manages stats, and integrates Doctrine DBAL for schema insights. - Dashboard:
DashboardControllerrenders a Blade view (dashboard.blade.php) for metrics. - API:
ApiControllerhandles metrics retrieval and query explanations via Gemini. - Console:
ShowStats&ClearStatscommands manage stats from the CLI.
Customization
- Views: Modify published Blade templates in
resources/views/vendor/queryoptimizer. - JavaScript: Extend assets in
resources/js/queryoptimizer. - Config: Adjust
config/queryoptimizer.phpas needed.
Troubleshooting
- Empty Dashboard: Check that the
log_pathfile is writable and receiving logs. - API Errors: Verify the Gemini API key and network connectivity.
- DBAL Issues: Ensure correct database configuration and driver.
Contributing
Contributions are welcome! Please submit a pull request or open an issue on GitHub.
License
Open-source under the MIT License.
oussemakh1/laravel-query-optimizer 适用场景与选型建议
oussemakh1/laravel-query-optimizer 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 oussemakh1/laravel-query-optimizer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 oussemakh1/laravel-query-optimizer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-14

