Web hosting
Website TTFB troubleshooting: find what delays the first byte
Time to first byte (TTFB) includes connection/TLS and the time the server takes before sending the first response byte. A high TTFB can come from network distance, proxy queueing, application/PHP work, database queries, external APIs, cache misses, or overloaded infrastructure.
Break timing into network and server components
Use curl/browser timing to record DNS, connect, TLS, start-transfer, and total time from more than one client region. Subtracting connection setup from TTFB helps distinguish path latency from origin processing.
Test both cache-hit and cache-bypass URLs when a CDN/page cache exists.
Measure origin application duration
Add server/request logs containing upstream response time or application timing. Profile PHP/runtime, database queries, template rendering, external HTTP calls, filesystem operations, and worker queue time.
A slow remote API can dominate TTFB even while local CPU is idle.
Check queueing and resource pressure
Inspect PHP/app worker saturation, CPU, memory pressure, disk latency, database connections, and load. More workers can reduce queueing only if the rest of the stack has capacity.
Compare slow periods with a normal baseline.
Optimize the longest segment first
Fix expensive application/database work, cache safe responses, move background tasks, or resize the constrained resource based on evidence. Re-run the same timing test after each change. Keep client region and cache state constant between samples so the comparison reflects the server change with the network path held constant.
- Separate DNS/connect/TLS/server time.
- Measure origin upstream time.
- Check worker/database queues.
- Retest the same URL after changes.