Profiling Queries: Finding Slow Pages in Laravel
Learn practical ways to detect slow queries, reduce query count, and improve response time.
Ethan Ward
October 28, 2025
6.2k199
A Laravel app feels slow most often because:
- too many queries (N+1)
- missing indexes
- loading too much data
- doing heavy logic inside loops
## Quick win: log queries locally
```php
DB::listen(function ($query) {
logger()->info($query->sql, $query->bindings);
});
```
This helps you see if your controller triggers 2 queries or 200.
## Reduce loaded columns
```php
$users = User::select('id', 'name')->get();
```
Instead of loading every column.
## Graph: where time is spent
```mermaid
flowchart TD
A[Request Time] --> B[DB Queries]
A --> C[Serialization]
A --> D[Template Rendering]
```
In the next tutorial, we will handle background failures and retries.
#Laravel#Performance#Advanced