How to get a list of running php scripts using PHP exec ()?

I need to know and kill if there are any processes executing the specified PHP script. Is it possible to get a list of processes that execute sample.php using exec () and a PHP script.

+5
source share
4 answers
exec("ps auxwww|grep sample.php|grep -v grep", $output); 

This will work, however, if PHP is running in CGI mode. If it works as an SAPI type, you will never see "sample.php" in the process list, just "httpd".

+16
source

No. Since PHP runs through apache / nginx. When accessing the command line, proccess is called PHP, not the actual name of your script.

+1
source

It depends on many factors, including the OS, version of PHP, etc., but you can try using signals to get a script to give you your name, and then terminate if it matches. Or, the script register its pid, and then compare with the running processes.

http://stuporglue.org/handling-signals-in-php/

0
source

this helped me kill rogue processes via the url parameter. I thought I would be participating in the discussion in case someone else showed the answers.

download yikes.php. identify the process identifier (this should be the first integer that you get in each index of the array). copy and paste it in url how? pid = XXXXX. and he left.

 //http://website.com/yikes.php?pid=668 $pid = $_GET['pid']; exec("ps auxwww|grep name-of-file.php|grep -v grep", $output); echo '<pre>'; print_r($output); echo '</pre>'; // exec("kill $pid"); 
0
source

Source: https://habr.com/ru/post/951260/


All Articles