I have had lots of problems in the past bit trying to kill external commands run by proc_open.
Others have suggested using ps to find the children of the pid returned by proc_get_status, but on my system this doesn't work. I'm using php-5.2.5 and apache-2.0.59 on linux kernel 2.6.21, and the processes I start with proc_open end up being owned by init (pid 1), not by the pid returned by proc_get_status.
I did notice, however, that the pid's of the processes were always above and very close to the proc_get_status pid. Using that information, I wrote a little function that takes the name of a command, the starting pid at which to search (which would be the proc_get_status pid), and optionally a search limit as arguments. It will use ps to list processes owned by apache (you may have to change this user name for your system), and search for the command specified. The limit tells how far above the starting pid to search. This will help if the command may have already exited, and you don't want to kill a process from a different session than the one you're working with.
Here's the code:
<?php
function findCommandPID($command, $startpid, $limit = 3)
{
$ps = `ps -u apache --sort=pid -o comm= -o pid=`;
$ps_lines = explode("\n", $ps);
$pattern = "/(\S{1,})(\s{1,})(\d{1,})/";
foreach($ps_lines as $line)
{
if(preg_match($pattern, $line, $matches))
{
if($matches[3] > $startpid + $limit)
break;
if($matches[1] == $command && $matches[3] > $startpid)
return $matches[3];
}
}
return false;
}
?>