Screens seems to be doing the trick! I am giving each screen a unique name so I don't need to recall the PID. I can terminate and access the screen via that name. I call the screen in a pseudo terminal environment (nice little code I found online).
$descriptorspec = array(
0 => array("pty", "w"),
1 => array("pty", "r"),
2 => array("pty", "r")
);
$process = proc_open("TERM=xterm screen -S ".$screenname, $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], "commands in shell\r");
echo fread($pipes[1], 1024);
fclose($pipes[0]);
}
my problem now is that if I attempt to fread() too much (ie, more than what is available in the terminal), The process hangs. I found this loop but it hangs as well:
while (!feof($pipes[1])) {
echo fgets($pipes[1], 1024);
}