Score:0

PHP-FPM slow log returning invalid results

us flag

The problem

I’m running PHP-FPM 7.4.30 under Apache 2.4 on RHEL 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 server 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

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

I haven't found any other reports of this issue, but I'm able to produce it every time I enable the slowlog on a production server as well as on a test server with just one user.

Thank you very much for any insight or assistance.

Score:0
ws flag

Did you by chance find an answer?

I have the same issue and have spent hours trying to figure it out. It's even more confounding that the php-fpm error log will have entries like

WARNING: [pool www] child 7559 exited on signal 15 (SIGTERM) after 166.818268 seconds from start

Or

[19-Jun-2023 16:24:56] WARNING: [pool www] child 7646, script '' (request: " ") execution timed out (66.168368 sec), terminating

However, that same PID is nowhere to be found in the slow log before it reaches request_terminate_timeout. Logic would seem to dictate a request that ran for 66+ seconds before getting terminated would also be logged to the slow log after 10s.

I am stumped

A.J. avatar
us flag
No, I have not made any progress on this issue.
A.J. avatar
us flag
I'm surprised that no one else has noticed that the PHP slow log doesn't work (at least on RHEL 8). However, it sounds like you might have the opposite issue: scripts that are running too long, but aren't recorded in the slow log.
Quantim avatar
in flag
This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://serverfault.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://serverfault.com/help/whats-reputation), you can also [add a bounty](https://serverfault.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/554585)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.