Parham Doustdar
Parham Doustdar

Reputation: 2039

How can I pipe input to a process?

I am trying to run a program using PHP and keep sending output to it. I've tried using exec() but as the documentation page says, it hangs, waiting for the process to return.

Is there something like exec() that would allow me to keep sending commands to a CLI application?

Please note that since the application is closed-source, I don't have the option of changing the application to look for a lock file or any other thing suggested as answers to similar questions.

Upvotes: 2

Views: 99

Answers (1)

sirlark
sirlark

Reputation: 2207

You are looking for the proc_open command. This command runs a process connecting its standard input and output to file descriptors opened as pipes in your program. What you write the 0 descriptor is taken as input on stdin by the process, and what it outputs can be read by your program as of from a file. The example code in the linked php documentation should get you going.

However, if you are trying to communicate with mysql specifically, rather use the built in mysql functionality of php

Upvotes: 1

Related Questions