nixCraft Linux / UNIX / Shell Scripting Forum

nixCraft

Linux / UNIX Tech Support Forum

Query - Apache and PHP

This is a discussion on Query - Apache and PHP within the Web servers forums, part of the Mastering Servers category; Some time when doing Top -d1.... i generally find 2 or 3 httpd process taking a lot CPU Server is ...


Register free or login to your account to remove all advertisements.

Go Back   nixCraft Linux / UNIX / Shell Scripting Forum > Mastering Servers > Web servers

Linux answers from nixCraft.


Web servers Discussion on Apache, Nginx and Lighttpd HTTP/web server and configuration issues.

Reply

 

Thread Tools Display Modes
  #1 (permalink)  
Old 7th December 2009, 12:15 PM
kasimani's Avatar
Senior Member
 
Join Date: Jul 2006
Location: India, Delhi
OS: CentOS, RedHat, Fedora, Ubuntu
Scripting language: Bash Scripting
Posts: 177
Thanks: 3
Thanked 1 Time in 1 Post
Rep Power: 5
kasimani is on a distinguished road
Send a message via Skype™ to kasimani
Default Query - Apache and PHP

Some time when doing Top -d1.... i generally find 2 or 3 httpd process taking a lot CPU

Server is Running PHP, apache, mysql etc....

So my question is, Is there anyway to find which PHP is taking lot CPU that is running behind the Httpd process

Here is the Screen Shots

top - 13:14:16 up 205 days, 19:01, 1 user, load average: 0.39, 0.32, 0.28
Tasks: 116 total, 1 running, 108 sleeping, 7 stopped, 0 zombie
Cpu(s): 9.2%us, 17.0%sy, 0.0%ni, 73.6%id, 0.0%wa, 0.2%hi, 0.0%si, 0.0%st
Mem: 7328716k total, 5206584k used, 2122132k free, 431128k buffers
Swap: 2031608k total, 92k used, 2031516k free, 3149540k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
22455 ibn 15 0 681m 14m 8604 S 19 0.2 0:07.75 httpd
22169 ibn 15 0 682m 14m 8520 S 1 0.2 0:10.57 httpd
22282 ibn 15 0 681m 14m 8148 S 1 0.2 0:07.06 httpd
Reply With Quote
  #2 (permalink)  
Old 7th December 2009, 08:02 PM
jaysunn's Avatar
Contributors
 
Join Date: Apr 2009
Location: 41.332032,-73.089775
OS: Red Hat Linux
Scripting language: bash awk sed
Posts: 793
Thanks: 116
Thanked 107 Times in 97 Posts
Rep Power: 14
jaysunn has much to be proud ofjaysunn has much to be proud ofjaysunn has much to be proud ofjaysunn has much to be proud ofjaysunn has much to be proud ofjaysunn has much to be proud ofjaysunn has much to be proud ofjaysunn has much to be proud ofjaysunn has much to be proud of
Default

Hello,
What I like to do is to use top and sort them by cpu. You can achieve this by invoking top with the -c switch.


Code:
[root@radio5 ~]# top -c
Once I find the PID of the highest CPU process, I now use the apache server-status to view what this process is doing.

You will need to setup apache server-status by uncommenting the following lines in httpd.conf. As well as adding ON to a option. A graceful restart is needed on apache.


Code:
# ExtendedStatus controls whether Apache will generate "full" status
# information (ExtendedStatus On) or just basic information (ExtendedStatus
# Off) when the "server-status" handler is called. The default is Off.
#
ExtendedStatus On
Code:
# Allow server status reports, with the URL of http://servername/server-status
# Change the ".your-domain.com" to match your domain to enable.
#
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Allow from all      
#    Deny from all
#    Allow from .your-domain.com
</Location>
You can then view server status by pointing your browser at:

Code:
www.domainame.com/server-status
You will get output like this:

Code:
15-0	4791	0/1967/1967	_	22.45	7	237	0.0	14.77	14.77	67.72.16.187	www.kyw1060.com	GET /pages/1137922.php HTTP/1.0
This shows me which php call is associated with the PID.

Also you can use the PID to run a strace on the process. This can help you see what is going on as well.


Code:
[root@radio5 ~]# strace -d 1142
HTH,

Jaysunn
__________________
Have a look at what I have been working on
http://www.shellasaurus.com

Last edited by jaysunn; 7th December 2009 at 08:04 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Hardware RAID query in rhel3 ES kumarat9pm CentOS / RHEL / Fedora 3 24th October 2009 03:01 PM
how to fire query for postgre sql via shell script sunil Shell scripting 3 15th September 2008 04:56 PM
Hard Link Query sharadgana Getting started tutorials 2 25th March 2008 12:11 AM
a query kavi Linux software 2 16th October 2005 06:16 AM
BIND 9 and Query-Source Ashish Pathak Linux software 2 7th February 2005 12:42 PM


All times are GMT +5.5. The time now is 08:56 AM.


Powered by vBulletin® Version 3.8.6 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40