putting PHP aside, you want something like the expect program under unix (might be windows versions).
expect is designed to interact with other programs, kinda like "if I see this then print this" stuff.
you could write an external wrapper that does this, then call that from PHP perhaps.
If, say, the program only needed prompting through its process, this would work.
I dont think you will be able to interact yourself from a webpage to the CLI program, because HTTP is stateless. You would only be able to submit a command, then your process is over.