Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I use NGINX/PHP-FPM. Sometimes I see a PHP-FPM process hogging the CPU. How can I tell which script is running in that process?

I know you can configure slow logging, but a) that's historical and b) I see some evidence that it causes instability with processes not restarting properly after logging slow requests, so I don't want to use that.

share|improve this question
    
How do you know it's a single script that's causing the CPU to spike, and not a queue of different requests? Is it just a single worker that's spiking? –  growse Nov 30 '12 at 11:45
    
It's just a single worker process. I can't be absolutely sure that it's not a queue of multiple requests to the same worker unless I can see what the worker is actually executing at the time, which is part of the reason for asking this question, but the server is generally quite lightly loaded, so it feel more like a single request which is not mainline path and is more expensive. –  Edward Hibbert Nov 30 '12 at 12:12
    
If you're pool is set to be dynamic with a max-workers >1, I'd expect a queue to spin up multiple workers. If that's not the case, it does indicate a long-running script. Another way of finding out is logging how long your webserver is taking to serve pages. PHP urls that take the longest might be what's pinning your CPU. XDebug is another option. –  growse Nov 30 '12 at 12:19
    
It's a fixed size pool, but processes exist which are not showing up in top as active, so I don't think it's a queue. Do you know of anything which parses an NGINX access_log to highlight patterns of slow requests? That's a wheel I don't want to reinvent... –  Edward Hibbert Nov 30 '12 at 12:23
    
Take a look at the request_time property of the nginx access log format. Documented at wiki.nginx.org/HttpLogModule –  growse Nov 30 '12 at 12:24

1 Answer 1

Recent (5.4+) versions of PHP include a status page with the FPM distribution.
You can configure this separately for each process pool, to show you what is being executed.

Alternatively, you can use APC or Xcache and get status from there.

I personally like Xcache since it shows quite extensive statistics.

share|improve this answer
    
And that includes details of the specific script name? I'm slightly worried that if I have a process hog then I won't be able to serve up the status page either from the same web server. There's no command line tool? –  Edward Hibbert Nov 30 '12 at 12:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.