☰
WORDPRESS / PRACTICE

How to Find a Slow WordPress Request with PHP-FPM slowlog

How to Find a Slow WordPress Request with PHP-FPM slowlog

If WordPress periodically hangs while the access.log shows only a long server response time, that is not enough to find the cause. The web server log shows that a request was slow, but not which stage caused it to stall.

PHP-FPM slowlog records the PHP call stack for requests that run longer than a configured threshold. This helps determine whether the delay is caused by a heavy WP_Query, a plugin, a theme, an external HTTP request, or a function that is repeating in a loop.

What PHP-FPM slowlog Shows

PHP-FPM slowlog is a separate log for slow PHP requests. When a PHP-FPM worker processes a request longer than the request_slowlog_timeout value allows, PHP-FPM writes information about the current call stack to the slowlog file.

The entry may show the PHP files and functions that were running when the timer was triggered. If the stack contains paths such as wp-content/plugins/plugin-name or wp-content/themes/theme-name, this is an important clue for further investigation.

Slowlog is not a complete profiler and does not always identify the exact cause of a delay. For example, a stalled external HTTP request may appear as a call from a WordPress library or plugin. Even so, the stack can narrow the investigation to a specific component.

  • access.log shows the duration of the HTTP response, while slowlog shows the state of the PHP code during execution;
  • the regular PHP error log does not necessarily contain the stack of a slow request;
  • slowlog is especially useful for intermittent problems that are difficult to reproduce manually.

How to Enable slowlog for a PHP-FPM Pool

Add these parameters to the configuration of the required PHP-FPM pool, not only to php.ini. On many systems, this is a file such as www.conf in the pool.d directory, but the exact path depends on the distribution, PHP version, and installation method.

For initial diagnostics, you can use a five-second threshold. On a production site, adjust it according to the normal response time so the log does not fill with expected slow operations.

  • make sure you are changing the configuration of the pool that handles WordPress;
  • create the log directory in advance if it does not already exist;
  • verify that the PHP-FPM user has permission to write to the log file or directory.
[www]
request_slowlog_timeout = 5s
slowlog = /var/log/php-fpm/wordpress-slow.log

Checking the Configuration and Reloading PHP-FPM

After editing the configuration, do not restart the service blindly. First, run a syntax check using the command available on your system. The binary name may include the PHP version.

If the check succeeds, reload PHP-FPM through systemd or the management tool used by your server. Reload usually applies the changes with less impact on current connections, but the exact behavior depends on the configuration.

  • example commands may look like php-fpm8.2 -t or php-fpm -t;
  • for the service, the command is often systemctl reload php8.2-fpm or systemctl reload php-fpm;
  • after the reload, make sure the PHP-FPM process is still running and that no errors appeared in the system log.
php-fpm8.2 -t
sudo systemctl reload php8.2-fpm
sudo tail -f /var/log/php-fpm/wordpress-slow.log

How to Reproduce the Problem and Find the Cause

After enabling slowlog, wait for the problematic request or carefully reproduce it. This may be an administrative page, search, cart, checkout, AJAX endpoint, or a specific URL that loads slowly.

At the same time, monitor slowlog in real time and note the request time. For a more accurate correlation, compare the slowlog entry with access.log: the URL, time, response status, and duration should approximately match.

Look for repeated paths and functions in the stack. If several slow requests point to the same plugin, check it first. If the stack stops in the theme, the problem may be in a custom template, hook callback, or database query.

  • wp-content/plugins — a potential source of the delay;
  • wp-content/themes — code from the theme or child theme;
  • wp-includes/class-wp-hook.php and similar files are often only an intermediate link, not the actual cause;
  • curl or AJAX requests waiting for an external service may appear as prolonged execution of a plugin function.
sudo tail -n 100 /var/log/php-fpm/wordpress-slow.log
sudo grep -E "plugins|themes|wp-cron|admin-ajax" /var/log/php-fpm/wordpress-slow.log

How to Interpret the PHP Stack

A single entry is not always enough to draw a conclusion. A slow request may be captured by slowlog at different points during execution, so collect several examples of the same problem. If the same file or function appears repeatedly, the likelihood of locating the cause correctly is much higher.

Pay attention to the type of delay. A heavy WP_Query is often related to a large volume of data, complex meta_query conditions, or missing appropriate indexes. An external HTTP request may be waiting for an API response, DNS, or a network connection. A loop or recursive call often repeats the same functions in the stack.

After locating the component, do not immediately edit the plugin files. First check for updates, caching settings, the possibility of disabling an unnecessary integration, and any known issue reported by the component developer.

  • a repeated plugin in the stack is a reason to test the site on staging or disable components safely and step by step;
  • slow SQL is not always visible directly in slowlog, so confirming it requires query analysis tools;
  • if the stack changes every time, the problem may be related to load, database locks, or an external service.

What to Check After Finding the Problematic Component

Slowlog answers the question “where is the code executing?” but not always “why is it slow?” After identifying the component, perform a separate investigation: review SQL queries, external API calls, result-set size, and how often the hook is triggered.

For WordPress diagnostics, you can temporarily use a profiling tool in a test environment or enable extended logging for a short period. Do not leave detailed debug mode uncontrolled on production: it can generate a large amount of data and expose internal information.

If a plugin is responsible, compare the behavior after disabling it on staging. If the problem disappears, record the URL, stack, execution time, and component versions before contacting the developer. This report will be much more useful than saying that “the site sometimes hangs.”

  • check the web server, PHP-FPM, database, and external proxy logs;
  • make sure the problem is not related to an exhausted memory_limit, max_children, or database connections;
  • do not increase max_execution_time as the first step: this may only allow the problematic request to run even longer.

Security, Log Size, and Disabling slowlog

The slowlog may contain file paths, function names, URLs, and other technical details. Restrict access to the log file to the web server user and administrators, and do not place it in a web-accessible directory.

Configure logrotate or another rotation mechanism. Without rotation, a recurring slow request can quickly increase the log size and consume disk space. Also control permissions on the parent directory: PHP-FPM must be able to write to it, while unauthorized users must not be able to read its contents.

After completing the investigation, increase request_slowlog_timeout to an appropriate operational value or disable slowlog. Continuous logging with an excessively low threshold creates unnecessary overhead and makes it harder to find genuinely important entries.

  • do not store slowlog in public_html or another publicly accessible directory;
  • check the owner, group, and permissions of the file;
  • configure limits for the size and number of archived logs;
  • delete or protect old logs after the investigation is complete.

Frequently asked questions

Do I need to add slowlog to php.ini?

No. request_slowlog_timeout and slowlog belong to the PHP-FPM pool configuration. Set them in the configuration file for the required pool, such as www.conf, if that pool handles the WordPress requests.

Why does the slowlog remain empty?

Check whether the request actually exceeds the configured threshold, whether PHP-FPM read the changes after the reload, whether the log directory exists, and whether the PHP-FPM process has write permission. Also make sure you are viewing the file for the correct pool and PHP version used by the site.

Will slowlog show a slow SQL query?

Not necessarily. slowlog shows the PHP stack at the time of the delay, but the SQL text may not be present. Database analysis requires separate logs or profiling tools, which should be enabled for a limited period and preferably in a test environment.

What request_slowlog_timeout should I set in production?

There is no universal value. The threshold should be higher than the normal execution time of regular requests but low enough to capture real hangs. An initial value of five seconds is only an example, not a mandatory standard.

Will increasing max_execution_time solve the problem?

Usually not. This setting only allows the PHP request to run longer and may increase worker load. First find the cause with slowlog, then change execution limits only if it is genuinely necessary.

Conclusion

PHP-FPM slowlog is a practical way to move from the fact that “WordPress is responding slowly” to a specific PHP file, plugin, or function. It is especially useful when the problem occurs intermittently and cannot be explained by access.log.

Use slowlog as a temporary diagnostic tool: set a sensible threshold, verify permissions and log rotation, compare the stack with web server logs, and after finding the cause, disable it or return it to a safe operational setting.

← All WordPress materials