views:

14

answers:

0

Hi all,

I have a c++ app, which I launch from a php script (see below). The app compiles, and runs fine when I interact with it on the cli on boths Windows and OSX (separate executables for each). When I launch the script on OSX the app and script both run fine, but when I run it under windows the app process refuses to die but sits idling using 0% CPU.

I have built an OSX version of my app, with a while(wait) { wait = false; wait = true; } loop at the end, and when I use this version, my script successfully kills off the process, but on Windows, the script refuses to die, and thus the request is not send back to the client.

When I step through with XDebug on Windows, I am able to parse $clusterManagerResult, so I know the app is executing properly, but I just can't kill the damned thing.

I know I can't use posix_kill( $pid, 9) and as such, and I've moved from exec() up to the proc_*() suite.

Anyone know a way to undeniably kill a spawned process under windows in php?

DJS.

<?
$commandString = "myapp -doStuff -withParams...";

// Define descriptor
// The internet is like a series of tubes.
$descriptor = array(
 0 => array("pipe", "r"),
 1 => array("pipe", "w")
);

$clusterManagerProcess = proc_open($commandString, $descriptor, $tubes);

if(is_resource($clusterManagerProcess))
{
 /* 
  * The $tubes now look like this:
  * 0 => writeable handle connected to child stdin
  * 1 => readable handle connected to child stdout
  */
 if(!feof($tubes[1]))
 {
  $buffer = fread($tubes[1], 1024);
  $clusterManagerResult = json_decode($buffer, true);
 }

 fclose($tubes[1]);
 fclose($tubes[0]);

 $status = proc_get_status($clusterManagerProcess);

 if($status['running'])
 {
  proc_terminate($clusterManagerProcess);
 }
 else
 {
  echo proc_close($clusterManagerProcess);
 }
}
?>