Skip to content

PHP-FPM slow log: finding the requests that drag performance down

Enable and parse the PHP-FPM slow log to identify slow stack traces, correlate them with application paths, and prioritise what to fix in production.

PHP-FPM’s slow log captures a stack trace for any request that exceeds a configurable wall-clock threshold. Unlike an application profiler, it has zero instrumentation overhead — FPM sends SIGQUIT to the worker process and the kernel dumps the current call stack, all without modifying the application. The result is a file of timestamped stack traces that shows you exactly which functions were executing when the request blew past your threshold.

How to verify

Check whether slow logging is currently enabled and whether the log file exists:

grep -E 'slowlog|request_slowlog' /etc/php/8.3/fpm/pool.d/www.conf
ls -lh /var/log/php-fpm/www-slow.log 2>/dev/null || echo "slow log not yet configured"
# If the file exists, show the last 40 lines (one entry is ~10 lines)
tail -40 /var/log/php-fpm/www-slow.log
# Count how many slow events have been logged today
grep -c "^$" /var/log/php-fpm/www-slow.log 2>/dev/null

What’s happening

When request_slowlog_timeout is set, FPM’s master process monitors running workers. Any worker that has been handling a single request longer than the timeout receives a SIGQUIT. The Linux kernel responds by dumping that process’s current call stack (via zend_get_stack_trace) into the slow log file, then the worker continues executing — it is not killed. The result is a non-intrusive snapshot of a live execution.

Each slow log entry contains the timestamp, pool name, worker PID, the script path, and a zend stack trace showing the function call chain at the moment of sampling. The trace reads bottom-to-top: the lowest line is the entry point ({main}), and the top is the function executing when FPM sampled the stack.

For requests that are slow because they block on external I/O (database queries, HTTP calls, file reads), the stack trace will show the blocking call — PDO::query, curl_exec, file_get_contents — at the top, which immediately tells you whether the bottleneck is PHP code or an external dependency.

The procedure

1. Enable the slow log in the pool configuration.

Edit /etc/php/8.3/fpm/pool.d/www.conf:

slowlog = /var/log/php-fpm/$pool-slow.log
request_slowlog_timeout = 2s
; Optional: limit stack trace depth to reduce log volume
request_slowlog_trace_depth = 20

Set request_slowlog_timeout to 2–5 seconds for a first pass. Setting it too low (under 500ms) floods the log with traces for every warm-cache miss; too high (over 10s) and you only catch catastrophic requests.

Create the log file and set permissions:

mkdir -p /var/log/php-fpm
touch /var/log/php-fpm/www-slow.log
chown www-data:www-data /var/log/php-fpm/www-slow.log
systemctl reload php8.3-fpm

2. Reproduce or wait for slow requests.

For an application with intermittent slowness, let the log accumulate for 30–60 minutes under normal traffic. For a known slow path, hit it directly:

time curl -s https://your-site.com/the-slow-page > /dev/null

3. Parse the slow log to find the most common slow calls.

Each entry block ends with a blank line. Extract the top-of-stack function from each block to find what is slowest most often:

grep -A1 '#0' /var/log/php-fpm/www-slow.log | grep -v '^--$' | grep -v '^#' | \
  sort | uniq -c | sort -rn | head -20

Extract the script paths to see which URLs are triggering slow requests:

grep 'script_filename' /var/log/php-fpm/www-slow.log | \
  awk '{print $NF}' | sort | uniq -c | sort -rn | head -10

4. Read a full slow entry to understand the call chain.

# Show the first complete slow entry
awk '/^\[/{if(found) exit; found=1} found{print}' /var/log/php-fpm/www-slow.log

A typical entry looks like:

[19-Jan-2026 14:23:07] [pool www] pid 12345
script_filename = /var/www/app/public/index.php
[0x00007f...] PDOStatement->execute() /var/www/app/src/Repository/UserRepository.php:87
[0x00007f...] App\Repository\UserRepository->findActiveUsers() /var/www/app/src/Service/UserService.php:42
[0x00007f...] App\Service\UserService->getList() /var/www/app/src/Controller/UserController.php:31
[0x00007f...] App\Controller\UserController->indexAction() /var/www/app/public/index.php:21

This trace reads: indexAction called getList, which called findActiveUsers, which called PDOStatement->execute() and was still waiting. The database query is the bottleneck.

5. Correlate with access logs.

Match the PID and timestamp from the slow log to the Nginx/Apache access log to find the exact URL, query string, and upstream response time:

grep '14:23:07' /var/log/nginx/access.log | grep 'UserController'

6. Lower the threshold incrementally.

Once you’ve fixed the worst offenders, drop request_slowlog_timeout to 1s and repeat. Work down until you’ve caught everything above your target p95 response time.

Common pitfalls

Not creating the log directory before enabling. FPM silently drops slow log entries if the path does not exist or is not writable. Always verify the file exists and is owned by the FPM pool’s user.

Setting the timeout below the OPcache warmup time. On application startup after a restart, the first request through each code path warms OPcache and may take 500ms–2s legitimately. Triggering slow log entries for this case produces noise that obscures real regressions.

Reading the stack trace top-to-bottom instead of bottom-to-top. Frame #0 is the innermost (currently executing) call; the highest frame number is the entry point. Most engineers find the culprit at frame #0 — the function PHP was stuck in.

Ignoring the script path in the entry. In WordPress or Symfony, the script path is always index.php — it’s the entry point, not the slow file. Always look at the full stack trace to find the actual slow function.

Running slow log with a 100ms threshold in production without log rotation. A busy pool at 100ms threshold can write gigabytes of slow log in hours. Configure logrotate for the slow log file and set a sane threshold before enabling in high-volume environments.

For applications where slow log analysis reveals deeper architectural issues — N+1 queries, missing indexes, synchronous external calls — the Stack Harbor managed operations service includes performance review and remediation support.