Start free trial
Start free trial Log in

14-day free trial. No credit card.

Debugging Laravel performance in production

A repeatable workflow, from "the /checkout page is slow" to "the third-party fraud API p95 grew 8x."

  • Guide
  • 2 min read

How do I debug Laravel performance issues in production?

Use a trace-based workflow: find the slow route via APM p95 dashboards, drill into the slowest individual requests to see their component spans, identify the dominant span (usually a DB query or external HTTP call), reproduce locally with matching seed data, fix, verify in production. Avoid live debugging. Your APM traces should contain enough context to diagnose without it. Laravel's nightwatch package records each request's queries, cache calls and outgoing HTTP calls, and NightOwl shows them on one timeline per request.

Updated

Debugging performance in production has a bad reputation it mostly earns, because the usual version is someone SSHing into a live box under pressure and poking at it with tools that make it slower. It doesn't have to be that. Done well, production performance debugging is boring: you already have the traces, you read the one that's slow, you find the span that owns the time, and you reproduce it somewhere safe to fix it. What separates the stressful version from the boring one is mostly whether you set up that visibility before you needed it.

The debugging workflow

  1. Identify the symptom precisely

    Which route? Which user segment? Which time window? 'The app is slow' is not actionable. 'POST /api/checkout p95 went from 400ms to 2.1s after 14:00 UTC on 2026-04-12' is.

  2. Pull a trace for a slow instance

    Find the slowest requests in the affected time window. Open a trace. APMs break the request into spans (DB queries, cache calls, HTTP, view rendering). The largest span is your starting point.

  3. Classify the bottleneck layer

    App code, DB, cache, external HTTP, or view rendering. DB is a frequent answer, and N+1 queries and missing indexes are frequent DB causes. Narrow fast.

  4. Reproduce locally with realistic data

    Seed staging or local from anonymized production. Hit the same endpoint with similar payloads. Reproduce with Telescope or Clockwork to see the request's queries, events and timings, and add Xdebug's profiler if you need function-level detail.

  5. Fix and deploy behind a flag

    Use a feature flag so you can roll back instantly. Verify fix reduces p95 in production before removing the flag.

  6. Document the root cause

    A one-paragraph post-mortem per incident beats repeating the same discovery six months later. Include the trace URL, the fix, and the monitoring gap that let it land.

Tools by situation

Situation Tool Why
Production trace neededNightOwl / Nightwatch CloudAlways-on per-request traces
Local call-level profilingXdebug + KCacheGrindFunction-level timing depth
Local request inspectionTelescope / ClockworkPer-request query + event detail
DB query plan analysisEXPLAIN ANALYZEPlanner decisions that matter
Production-safe profilingExcimer (sampling profiler)Low-overhead, sampled
Memory debuggingmemory_get_peak_usage in middlewareCheap and precise

What you should never do in production

  • Run Xdebug, which slows down every request, and much more with profiling on
  • Drop into tinker on a live server. One typo and you've mass-updated a table
  • Add dd() or dump() calls, which print debug HTML into real users' responses
  • Turn on the database's general query log, or DB::enableQueryLog() in a long-running worker, which grows quickly and adds load (the in-memory query log also keeps growing until the worker restarts)
  • Run EXPLAIN ANALYZE on write queries, which actually executes them

Open the slow request and read its timeline

NightOwl records each request's DB queries, cache calls and outgoing HTTP calls with their durations on one timeline. Open a slow request and you can see which span took the time, without reproducing it.

No credit card needed.

Terminal
composer require nightowl/agent
php artisan nightowl:install
php artisan nightowl:agent

Frequently asked questions

Anything else, write to support@usenightowl.com

How do I debug Laravel performance issues in production without breaking things?

The safe sequence: (1) reproduce locally with seeded data that matches production shape, (2) use Laravel Telescope or Clockwork in staging to identify the bottleneck layer (app code, DB, cache, external HTTP), (3) add targeted instrumentation or APM visibility in production, (4) verify the fix lands before removing the instrumentation. Avoid running debuggers or tinker on production. Use APM-level traces instead.

What's the fastest way to find why a Laravel endpoint is slow?

Get a per-request trace of the slow endpoint. APMs give you this: the request is broken into spans (DB queries, cache calls, external HTTP, view rendering) with durations. The largest span is the bottleneck. Often it's DB queries, usually an N+1 or a missing index. If it isn't, look at external HTTP first, then view rendering, then cache misses.

Can I use Xdebug for Laravel performance debugging?

For call-level profiling, yes: Xdebug's profile output loaded into KCacheGrind or Qcachegrind shows where time is spent at the PHP function level. Don't run Xdebug in production. Its overhead is too high. Use it locally with a reproduction of the slow production case. For production-safe profiling, use an APM or a sampling profiler such as Excimer.

How do I tell if a Laravel performance regression was caused by my deploy?

Compare p95 latency per route before and after the deploy timestamp. If p95 for specific routes jumped immediately after deploy, the deploy is the cause. Look at the diff since the last deploy for changes to the affected controllers, Eloquent queries, or middleware. Roll back if the regression is severe while you investigate.

Should I use EXPLAIN ANALYZE on slow production queries?

Yes, but carefully. EXPLAIN ANALYZE actually runs the query: safe for SELECTs, dangerous for anything that mutates state. For write queries, use EXPLAIN (without ANALYZE) which returns the plan without executing. Compare plans between expected (from local reproduction) and actual (production). Differences in index usage or join order often explain slowness.

How do I debug Laravel memory issues in production?

Log peak memory per request with request context (route, user). Aggregate by route to find outliers. For individual problematic requests, reproduce locally with the same input and use PHP's memory_get_usage at key points to narrow down where the spike happens. See our memory-usage guide.

What causes sudden Laravel latency spikes under normal load?

Common causes: (1) a cache that warmed up during deploy is now cold after eviction, (2) database statistics gone stale causing the query planner to pick a bad plan (run ANALYZE), (3) a cron job running in-process that wasn't there before, (4) autoscaling bringing up new workers without connection pool capacity, (5) a third-party API you depend on went slow. APM per-request traces distinguish these fast.

How do I avoid debugging in prod?

Three practices: (1) seed staging from anonymized production data so you can reproduce realistic bottlenecks, (2) invest in an APM that records enough context to debug from traces alone, (3) set per-route latency SLOs and alert on regressions, so you catch issues before they need live debugging. Debugging in prod is what you fall back on when those fail. In NightOwl that means a duration threshold per route, which alerts when a single request crosses it rather than on a sustained p95 regression.

Flat pricing, whatever your traffic does

Every plan starts with a 14-day free trial. No credit card needed.

Hobby
$5 a month

One app for a side project. Issues and alerts, with a 14-day dashboard window.

Start my 14-day trial
TeamRecommended
$15 a month

Up to 3 apps and 5 people per team. Full history, the MCP server, data clearing and agent health.

Start my 14-day trial
Agency
$69 a month

Unlimited client apps and people, one overview of every app, and apps you can hand over.

Start my 14-day trial

Related

Debug your next slow page from its trace

NightOwl keeps each request's timeline, so the evidence is already there when someone reports a slow page. No credit card needed.