Is there a way to see which php script is hogging the cpu?

I am running wordpress on nginx with spawn-fcgi on centos6. I have a lot of traffic coming through this server and the load on the cpu is often fine but sometimes the cpu gets maxed out at 99% for a long period of time and the top command says that the culprit is a few php-cgi processes. Is there any way for me to see what php script is causing my cpu to max out?

Related posts

Leave a Reply

2 comments

  1. This sounds like a job for ps -ef with grep and some filtering of your top display using the PID’s you find. I am not sure what your processes look like BUT say you are looking for generic php processes.

    You can do:

    ps -ef | grep php
    

    ps -ef will grab all of the processes in a decently detailed way and grep will filter the results to only return what you want. Next you crack open top with the -p flag for pid’s and pass it a list of the pid’s you found, comma seperated. For example:

    top -p 123,456,789
    

    That should let you monitor only the ones you want and you can reference the results of ps -ef | grep to match the pid’s in top to the particular scripts in question. Hope this helps.