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.

There is a question that is similar to what I want to know here on server fault: How can I find exactly which PHP scripts are taking up all server resources? but I don't think any of the answers answer my question.

Today I was sent a screenshot by one of my clients. He had no idea what it meant, so he sent it to me to explain it to him. The image was sent by his hosting provider. My client's site is running slow, and I guess he asked the hosting guys why, so they sent him that image. The image appears to be a screenshot of the top command, and it shows that a file is taking up 90%+ of the CPU. I find this really interesting, and would love to know how to do that myself.

As I said, the screenshot appears to be the top command, but when I run top, and get the server busy, I do not get the same kind of result. I make sure that the script I run takes up some CPU with an infinite loop, but all I get is apache2 as the Command that is using up the CPU, while their screenshot shows:

/usr/bin/php /path/to/index.php

This is what the screenshot looks like:

PID  USER     PR NI VIRT RES  SHR  S   %CPU %MEM TIME+    COMMAND
1234 username 16 -2 134m 26m  7528 R   98   0.2  00:00:50 /usr/bin/php /path/to/file.php

And mine looks like this:

PID   USER     PR NI VIRT  RES  SHR  S   %CPU  %MEM TIME+    COMMAND
19632 www-data 20 0  44432 18m  3608 S   27.1  0.9  00:00:82 apache2

Notice how theirs shows /usr/bin/php and the path to the file that is hugging the CPU, but mine just shows apache2, which really tells me nothing useful.

I've always wanted to do this kind of thing and figure out what file is using up the CPU, now, my question is, how do they do that with top? I know I can use a profiler, and in fact, the question I liked to above has two nice suggestions, but I am curious as to how they do it with top.

Thanks in advance.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The difference between your two systems is apparently that on your client's system PHP run as a CGI executable (which is a common option with hosting providers) and on your system, it runs as an Apache module. CGI means that a separate program is started whenever a PHP script needs to be executed, which is listed in the top output. Running it as an Apache module on the other hand means that the PHP interpreter is just a subroutine of Apache without it's own process and can't be listed in top.

To find out similar informations just like with top in the CGI case, you could try to use ApacheTop.

share|improve this answer
    
I was afraid it had to do with the way php was running. Thanks for the quick answer. I do use apachetop, but I wanted to know how they were doing it with top. Thanks a lot man. –  Buzu Feb 16 '12 at 10:23

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.