The Apache Haus Forum

Forum Topics => Scripting Languages => Topic started by: mario on March 02, 2009, 02:17:40 PM

Title: PHP getting Apache pids or PHP pids
Post by: mario on March 02, 2009, 02:17:40 PM
Sometimes it is usefull to get the PIDs from Apache or PHP which runs over FCGID to kill all the processes if it hangs up. Sometime I had that with the non thead safe version (NTS) to use its performance.

Code: [Select]
<?php
$wmi 
= new COM('winmgmts://');
$processes $wmi->ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'httpd.exe'");
foreach(
$processes as $process){
    echo 
'cmd line: '$process->CommandLine ' --> pid: '$process->ProcessId .'<br />';
}
//reference http://msdn2.microsoft.com/en-us/library/aa394372.aspx
?>


or replace httpd.exe with php-cgi.exe and that kill it instead of print it out.

Notice: if you want to kill php-cgi processes you have to run that script with the php module in apache  ;) Otherwise the script maybe kills itself.