What PHP Scripts are Running in Apache?

If you run PHP through Apache (as a module rather than standalone), then it can be quite hard to track down which scripts are actually running at any given time on your server. This is particularly true on production environments where you can’t attach tracing (e.g. strace) to Apache.

However, there is a way to tell using the command lsof.

If you run the following in the root directory of your web application:

sudo lsof +D /var/www/yourwebapp | grep php

It will give you a list of all the PHP scripts that are currently open right now. Very handy to “see” inside what apache is doing and track down possible culprits for things like performance issues.

Note you need to have sudo access to do this as you need to be able to access the files open by the user that started apache.