halilcosdu/laravel-slower
Detects slow Laravel database queries, logs them, and uses optional AI recommendations to suggest indexes and other optimizations. Configure thresholds, enable/disable monitoring, and run with Laravel 10–13 on PHP 8.2+ for actionable performance insights.
DB::listen), making it non-intrusive for existing applications.EXPLAIN, INSERT), and AI toggle provide granular control over monitoring scope.EXPLAIN ANALYZE). Teams using SQL Server or Oracle may need adjustments.slow_log), adding ~500MB–1GB storage for high-traffic apps (configurable retention via slower:clean).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| AI API Costs | High | Disable AI (ai_recommendation=false) or use a budgeted OpenAI key. Monitor usage via openai-php/laravel logs. |
| Query Sampling Bias | Medium | Validate threshold (SLOWER_THRESHOLD) against real-world slow queries (e.g., 100ms vs. 1s). |
| Migration Impact | Low | Zero-downtime: Install during off-peak hours; test with enabled=false first. |
| Vendor Lock-in | Low | Exports raw EXPLAIN data; recommendations are SQL-agnostic. |
| Performance Overhead | Medium | Benchmark with enabled=true in staging; ignore high-frequency queries (e.g., ignore_insert_queries). |
AI vs. Manual Review:
Query Threshold:
OpenAI Reliability:
Storage and Retention:
slower:clean.)Database Compatibility:
EXPLAIN parsing for other DBs?SET SHOWPLAN_TEXT ON.Integration with Observability:
Premium Features:
Pre-Migration:
DB::enableQueryLog().SLOWER_THRESHOLD based on baseline query performance.Installation:
composer require halilcosdu/laravel-slower
php artisan vendor:publish --tag="slower-config"
php artisan vendor:publish --tag="slower-migrations"
php artisan migrate
Configuration:
ai_recommendation=false) to avoid costs during ramp-up.ignore_insert_queries=true).app/Console/Kernel.php:
$schedule->command(\HalilCosdu\Slower\Commands\AnalyzeQuery::class)
->dailyAt('3:00')
->withoutOverlapping();
$schedule->command(\HalilCosdu\Slower\Commands\SlowLogCleaner::class)
->daily()
->runInBackground();
Post-Migration:
slow_log table growth and adjust slower:clean frequency.EXPLAIN ANALYZE before/after).| Component | Compatibility Notes |
|---|---|
| Laravel 10–13 | Fully supported; no breaking changes in v2.x. |
| PHP 8.2+ | Requires named arguments (PHP 8.0+) and attributes (PHP 8.0+). |
| Databases | PostgreSQL/MySQL: Full EXPLAIN ANALYZE support. SQL Server/Oracle: Partial. |
| OpenAI API | Uses openai-php/laravel v0.18.0; may require API key rotation. |
| Third-Party | No conflicts with Laravel Telescope, Debugbar, or similar query tools. |
Phase 1: Monitoring-Only Mode (2–4 weeks):
enabled=true), disable AI (ai_recommendation=false).Phase 2: AI-Assisted Optimization (1–2 weeks):
ai_recommendation=true).SLOWER_THRESHOLD=500).Phase 3: Automated Indexing (Future):
.env and config/slower.php for changes (e.g., threshold, ignore_* rules).env() or a secrets manager (e.g., AWS Secrets Manager).openai-php/laravel to avoid breaking changes (e.g., API deprecations).DB::listen is enabled globally (check AppServiceProvider).openai-php/laravel logs for rate limits.slower:clean days or archive logs to S3.HalilCosdu\Slower\Services\Analyzer for DB-specific logic.enabled=true under load.runInBackground).How can I help you explore Laravel packages today?