PHP-FPM slow log returning invalid results

A

Anonymous

Guest
Hi there.

I'm trying to use PHP's slow log to test my sites for any slow-running scripts. Up to now, I haven't had any luck getting this to work, and I wanted to reach out to the forum to see if anyone else has experienced the same.

The problem

I'm running PHP-FPM 7.2.11 under Apache 2.4 on Rocky Linux 8, and I'm not able to get PHP's slowlog to work properly. It won't return valid information about long-running scripts.

When I enable the slowlog -- even with a high value for request_slowlog_timeout like 10 seconds or more -- I see many entries appear in the log, including scripts that I know are not long-running. The list appears random, displaying backtraces for a large variety of scripts and functions inside them. There's no obvious pattern. I'm sure that the information returned is not valid. These scripts simply do not take that long between request and returning a result to Apache.

What should happen

According to the PHP documentation, the slowlog should flag only those scripts that ran for more than a certain time since the request to the script was made. In other words, it should measure the time between the request and when the script finished running. However, this is not what happens when I enable the slowlog.

What seems to be happening

My theory is that the slowlog is not measuring the runtime of individual requests that come from Apache, but rather of the time that a child process has been running. Since child processes can run for a rather long time, they may appear to be long-running scripts for the slowlog. When the slowlog sees that a child process has run for more than request_slowlog_timeout, it outputs a backtrace of the currently running script (which could be anything running at that moment in time).

My questions

  • Why does PHP-FPM display invalid entries like this in the slowlog? Is it not able to detect the beginning of a request?
  • How do I configure the slowlog to record only what's intended: the run time of a single request?

Thank you very much for any insight or assistance!
 
  • Enable PHP-FPM slow log: Modify the PHP-FPM pool configuration to enable logging of slow requests. This helps identify scripts or processes causing performance issues.
  • Set a slow log threshold: Specify a threshold for slow PHP requests in the PHP-FPM pool configuration. Requests exceeding this threshold will be logged for analysis.
  • Analyze the slow log: Review the slow log to identify the slow requests and determine the root cause of the performance issues. Look for patterns or specific scripts that consistently appear as slow.
  • Optimize slow requests: Once the slow requests are identified, investigate and optimize the scripts causing the slowdown. This may involve debugging, code optimization, or caching techniques to improve performance.
  • Monitor and repeat: Continuously monitor your server and log slow PHP requests to identify ongoing performance issues. Regularly analyze the slow log and optimize as needed to maintain optimal PHP performance.

By following these steps, you can effectively log and fix slow PHP requests on your server, improving the overall performance and responsiveness of your PHP applications.
 
Back
Top