LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   How to know what PHP script is hanging the CPU? (https://www.linuxquestions.org/questions/linux-server-73/how-to-know-what-php-script-is-hanging-the-cpu-695589/)

pawwa 01-07-2009 10:11 AM

How to know what PHP script is hanging the CPU?
 
Hi LQ, this is my first post here, this is a great community.

I`m interested if anyone knows how could I find what particular php script (or java program, cgi, or whatever) is hanging the CPU, and running on apache web server? Is there a module for that?

Thanks.

dkm999 01-07-2009 08:25 PM

If you get control of the CPU again somehow, look in the Apache log to find out what the last-accessed script was.

It is important, though, to understand what you mean by "hanging". On my systems, each PHP script has a maximum time that it is permitted to run before the Apache web server kills it. In such a case, the browser that referred to the script will get no response, so it will appear that the server has hung, but in fact, the server is doing just fine.

To get more information on this, see if you can have a shell session to the server in parallel with the web browser. When the browser hangs, type a command to the shell session (top is a good choice); if the server is still alive, you will get a response to your command. Immediately visit the apache access log, and look at the recent entries there. You might also look at the error log, to see if there are any complaints about scripts taking too long. A good text editor running under your shell would be a great assist.

pawwa 01-08-2009 05:02 AM

Thanks. I think this needs more discussion.

Quote:

Originally Posted by dkm999 (Post 3400589)
On my systems, each PHP script has a maximum time that it is permitted to run before the Apache web server kills it.

Yeah, but a script could be access over and over again, and system could be less responsive.

Quote:

Originally Posted by dkm999 (Post 3400589)
If you get control of the CPU again somehow, look in the Apache log to find out what the last-accessed script was.

What if we are talking about shared hosting environment, where there are hundreds of separate access logs. I mean, processing them all manually would be a pain in the ass.

I thought there was a module for this? I tried googling but I have found nothing.

dkm999 01-08-2009 11:55 AM

I am not aware of any module that can do this for you.

If this were my problem to solve in a shared host environment, I think I would not try to handle the mass of logfiles manually; that is what scripts are for. Digesting a list of logfiles would be pretty easy either using awk and sed or perl, depeding on which you are comfortable with.


All times are GMT -5. The time now is 02:11 PM.