halilcosdu/laravel-slower
Detect and log slow Laravel database queries, then get AI-powered suggestions for indexes and query improvements. Configurable thresholds, can run with or without AI, and supports Laravel 10–13 on PHP 8.2+.
Order::create() is slow").IN (...) clause in UserController@search is hitting a full table scan").EXPLAIN operations to background workers.SELECT * FROM users queries" in one dashboard row.slower:apply --dry-run).SlowQueryFirstSeen events to trigger error budgets (e.g., "Block deployments if >5 new slow queries appear").origin context to include Laravel Horizon jobs or API gateway metadata.Adopt if:
IN (...) clauses) where fingerprinting reduces noise.EXPLAIN analysis).Look elsewhere if:
*"Slower v3.2.0 is now production-grade—turning database optimization from a staging exercise into a real-time observability powerhouse. Key upgrades:
SELECT * FROM orders WHERE user_id = ?) so you see one row per query shape, not one per request. Saved our support team 12 hours/week triaging duplicate alerts.Example win: We caught a 1.8s query in our UserController@search endpoint—fingerprinting showed it was the same IN (...) clause across 400 requests. The AI suggested a composite index, which we applied via a one-liner. Result: Query time dropped to 40ms, saving $8K/year in DB costs.
Ask: ‘Should we enable queued analysis to reduce peak-hour load, or start with synchronous mode for simplicity?’"
*"Slower v3.2.0 is now safe for production and packed with context. Here’s how to use it:
Key Features:
php artisan slower:fingerprint to retroactively group identical queries. Now you’ll see:
-- Before: 100 rows for `SELECT * FROM users WHERE id IN (?)`
-- After: 1 row with `occurrences: 100`, `avg_duration: 300ms`
Origin: `UserController@search` (app/Http/Controllers/UserController.php:42)
Query: `SELECT * FROM users WHERE email = ?`
capture.sample_rate: Log only 1% of queries to reduce overhead.EXPLAIN work to background jobs.SELECT * FROM users WHERE email = ?).Setup:
php artisan migrate.php artisan slower:fingerprint (idempotent; runs in chunks)..env:
SLOWER_CAPTURE_SAMPLE_RATE=0.01 # 1% of queries
SLOWER_ANALYZE_QUEUE=slow_analysis
event(new SlowQueryFirstSeen($query));
// → Triggers Slack/email via Laravel Notifications.
Trade-offs:
sample_rate).Example Workflow:
UserController@search.php artisan slower:apply --dry-run (future feature).Ask: ‘Should we integrate the SlowQueryFirstSeen event with our existing alerting (e.g., PagerDuty), or build a custom dashboard first?’"*
How can I help you explore Laravel packages today?