The PHP-FPM slow log helps you identify PHP scripts that take unusually long to execute. It is useful for troubleshooting slow websites and finding performance bottlenecks caused by PHP scripts, plugins, database operations or external requests.
Enable the slow log
Add the following settings to the PHP-FPM pool configuration:
slowlog = /var/log/slow.log
request_slowlog_timeout = 10s
The timeout can be adjusted depending on your requirements. For example, with 10 seconds configured, PHP-FPM will log requests that take longer than 10 seconds to execute.
Monitor the log
You can monitor the slow log in real time using:
tail -f /var/log/slow.log
The log can provide information about the PHP script that was running when the timeout occurred. This can help you identify the source of slow requests and investigate the underlying cause.
Disable the slow log after troubleshooting
The slow log is intended as a troubleshooting tool. Once you have finished investigating the issue, disable it again or remove the timeout setting to avoid unnecessary logging.
Note: A slow PHP request does not necessarily indicate a PHP error. Slow requests can be caused by application code, database queries, external network requests, image processing or other operations.