PHP and HTTPD – Find Which PHP Script is Running on Each HTTPD Process

apache-2.2linux

I'd like to know a way of inspecting HTTPD processes to find which PHP script is running on them.

I already did a "netstat" and found that some processes held DB and Network sockets for too long and now i want to know what scripts are causing it.

Btw, i'm using Linux.

Best Answer

You need to have Apache module mod_status enabled (CentOs main Apache config file is located at /etc/httpd/conf/httpd.conf)

LoadModule status_module modules/mod_status.so

with option ExtendedStatus on (this is to be set in the same config file as above)

# 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

and some access rights set for that (replace below XXX.XXX.XXX.XXX with your IP - this is to be found in the same config file as above)

# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Change the ".example.com" to match your domain to enable.
#
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from localhost 127.0.0.1 XXX.XXX.XXX.XXX
</Location>

Finally you will be seing what each HTTPD process is doing by accessing http://your-server-name/server-status

This will show the pids and URLs currently being processed in the way presented here.