Guides

Logging Slow PHP Pages

Using the PHP-FPM slowlog to track pages that are performing slowly.

Overview

Monitoring the performance of your PHP scripts and webpages is critical to scaling your system, and ensuring you know about issues before they cascade into downtime.

This guide will teach you about the PHP-FPM slowlog which allows you to log slow PHP responses.

How to enable PHP-FPM slowlogging

You need to locate your php-fpm config file in order to make these changes. By default this will be in /etc/php-fpm.d/ or /etc/php/7.4/fpm/pool.d (or your php version) and is often simply called "www.conf".

You can run this to try and find it:

sudo grep -R "request_slowlog_timeout" /etc/

Edit that file and (assuming the slowlog options are commented out, which they are by default) add the following lines to the bottom of the config file:

slowlog = /var/log/php-slow.log
request_slowlog_timeout = 2s

In the above example you will write logs for any requests taking over 2 seconds to /var/log/php-slow.log. You can customize this to suit your installation.

Example PHP slowlog

As you can see below you are given the function and the file that are slow. This is extremely useful for speeding up PHP-FPM.

[0x00007f53de01d7d0] curl_exec() /srv/www/example.com/httpdocs/wp-includes/Requests/Transport/cURL.php:162
[0x00007f53de01d710] request() /srv/www/example.com/httpdocs/wp-includes/class-requests.php:379
[0x00007f53de01d3e0] post() /srv/www/example.com/httpdocs/wp-includes/http.php:181
[0x00007f53de01d120] wp_dashboard_setup() /srv/www/example.com/httpdocs/wp-admin/index.php:15

Ready to run your test?
Launch your locust test at scale.