Start with the user-visible symptom. If a checkout page is slow, establish response times at the edge, web server and application first. A database connection, PHP worker queue or external dependency may explain the delay; logging only the function that happened to be on the stack can direct attention to the wrong component.
Understand the two key PHP-FPM pool settings
The PHP-FPM configuration manual describes request_slowlog_timeout as the threshold after which a PHP backtrace is written to the configured slowlog file. A value of zero disables this function. The separate request_terminate_timeout setting can stop requests after an allowed duration; it is a process-control limit, not the same as collecting a diagnostic trace. These settings belong to the appropriate FPM pool configuration rather than an arbitrary application PHP script.
For a low-traffic laboratory pool, a small threshold can make demonstrations easy. In production, the threshold should reflect realistic service-level objectives, normal long-running operations and the volume of logs generated. Changing it without consultation can create noisy output or mask relevant events. Review config syntax, restart or reload with a documented change plan, and keep a rollback path.
Choose a threshold by measuring normal work
Collect representative response-time distributions before choosing a slowlog threshold. Separate quick page loads, report generation and other operations with different legitimate durations. An occasional slow request may be tolerable, while a consistent high percentile can indicate a user-facing problem. Correlate the event time with CPU, memory, database latency, external API calls and worker utilization.
Be careful with logs: file paths, request identifiers and stack data can reveal sensitive implementation details. Restrict file permissions, establish retention and avoid copying production traces to public issue trackers. A monitoring account should see only the operational data it needs.
Read stack traces alongside pool capacity
A slow PHP request may appear while an application is waiting on a lock, database or remote service. A repeated trace near the same call suggests a hypothesis but still needs validation using profiling or dependency metrics. Also examine the FPM process manager configuration, active and idle workers, listen queue and max children reached signal when queueing seems likely.
The official PHP-FPM status documentation lists metrics such as active processes, idle processes, listen queue, max children reached and slow requests. The slow requests counter records events crossing the configured threshold; it does not count every HTTP request with a high end-to-end duration. A request may spend time waiting upstream or downstream of PHP-FPM. This is why correlated observability matters.
Turn the finding into a controlled improvement
Once a suspect function or dependency is identified, reproduce the problem in a permitted test environment with representative data. Compare before and after using the same metrics and load. A query index may help, but only if the execution plan and workload justify it. Increasing worker count may temporarily reduce queueing but can exhaust memory or worsen database contention when the underlying problem remains.
After fixing the issue, keep an appropriately scoped threshold for regression detection and review slowlog volume periodically. A good diagnostic record explains the time window, service impact, observed trace, corroborating metrics, change made and remaining uncertainty. Slow logging creates value when it narrows an investigation and informs evidence-based performance work, not when every backtrace is treated as an emergency.