PHP itself is capable of running interactive; its the http protocol that is stateless.
To do what you want to do, and not clog up the httpd, than you would want to write a socket handler and execute it on an infinite loop in the background. So launch that on the command line. It then needs to store any information and pick any information up through a file or db. You can pipe directly to the running process, but frankly simply writing a queue of commands into a filesystem file is a lot easier to do in PHP than piping into a running process.
This is why I have suggested the use of Java RMI since they establish persistent connections.
header('HTTP/1.1 420 Enhance Your Calm');