Logging Slow PHP Pages

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


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/
[0x00007f53de01d710] request() /srv/www/
[0x00007f53de01d3e0] post() /srv/www/
[0x00007f53de01d120] wp_dashboard_setup() /srv/www/

Ready to run your test?
Start your first test within minutes.