Prashant Verma
Prashant Verma

Reputation: 1

How to know which PHP script is currently running in Ubuntu 16.04?

I am running virtualmin on ubuntu 16.04 with Wordpress website. Most of the time I get 10-20 PIDs of php-cgi. I want to know which php script is currently running or executed php scripts log. As I recently bought VPS so I am new to server management. So, I am unaware of commands that can do that. However, I did tried some of them by searching my question but none of them resulted in running script.

Server:Apache PHP: PHP 7 CGI RAM: 12 GB CPU: Intel E5

Upvotes: 0

Views: 1083

Answers (2)

Jonas Malm
Jonas Malm

Reputation: 429

Old question, but I just wanted to share how I do it, as one possible solution to the OP's question.

If you have bash access to the server and htop installed you can execute htop, then search for php-cgi (by pressing F3) and then pressing F5 for tree view, which will show each process and originating script. I'm sure there are other ways of achieving the same result, but this is how I've learnt to do it.

Upvotes: 1

gview
gview

Reputation: 15361

Your question is unclear. You have multiple cgi processes which could be running concurrently. Are you looking to have an idea of what php scripts are running in a log? Then you would get that from configuration of a php-fpm access log which includes the name of the php script running.

In the configuration file for the pool you want to log, you need to point to a directory writeable by the php-fpm process user:

access.log = /var/log/php/access.log
access.format = %R – %u %t \”%m %r%Q%q\” %s %f %{mili}d %{kilo}M %C%%”

This log formate puts out pretty much all available information.

Key are these 2 items:

%r - Request
%f - Script filename

Make sure you restart php-fpm after you make any changes like this to the configuration.

Upvotes: 0

Related Questions