The Apache Haus Forum

Forum Topics => Scripting Languages => Topic started by: mario on May 04, 2009, 02:51:58 PM

Title: [PHP] Get apache pid and path
Post by: mario on May 04, 2009, 02:51:58 PM
Sometimes it is nice to see which apache runs. On my dev machine I run several apache in different versions for testing.
I made a small command line php script for seeing which apache runs. I named it pid.php


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 "\r\n";
}
//reference http://msdn2.microsoft.com/en-us/library/aa394372.aspx
?>


on the command line php.exe pid.php
Code: [Select]
I:\server2\php>php pid.php
cmd line: "I:\server2\apache\bin\httpd.exe" -w --> pid: 3184
cmd line: I:\server2\apache\bin\httpd.exe -d I:/server2/apache --> pid: 2236

I:\server2\php>