Home » Php » How to get the Windows Process ID of a PHP COM Object (MS Word)?

How to get the Windows Process ID of a PHP COM Object (MS Word)?

Posted by: admin February 25, 2020 Leave a comment

Questions:

Is it possible to retrieve the Windows Process ID (PID) from an instance of Microsoft Word created through a PHP COM Object?

I am using MS Word to process documents and sometimes the Background Process of MS Word get’s hung up on my server, I can see them by running: tasklist /fi "IMAGENAME eq WINWORD.EXE"

tasklist cli output

I would like to be able to grab the PID immediately after creating the COM Object so that I can kill that specific process later and not just wipe out all of the WINWORD.EXE instances.

<?php

$word = new COM("Word.Application");

//$PID = $word->SomeWayToGetPID();   -----????

...document processing

$word->Quit();
$word = NULL;

?>

NOTE: there will be multiple users simultaneously creating MS Word instances so simply comparing the list of PID’s before and after will not be accurate.

How to&Answers: