-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Process] Provide interactive input. #19558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Instead of always closing the input pipe after exhausting the input buffer or resource leave the input pipe open. - setInputInteractive(): controls interactivity - appendInputBuffer(): convenience method for writing additional input - setInput(): now allows setting new input if interactive
The diff is a tad misleading give that it looks like |
You can already do this by using an iterator as input, see |
@nicolas-grekas Looks promising. I actually developed this on 3.0.x and rebased. Finally got around to cleaning up and trying to upstream. I'll take a look and close if nothing further. |
It seems to work in principal, but interestingly it does not write every time My use-case is basically (paraphrased): $process = new Process('cat');
$input = new InputStream();
$process->setInput($input);
$process->start(function ($type, $buffer) use($input) {
echo "+ $buffer";
if (/*some buffer output */) {
$input->write(PHP_EOL); // continue
}
}
while (true) {
echo "main loop\n";
$process->isRunning(); // triggers reading of pipes
$process->checkTimeout(); // can trigger exception
sleep(1);
}
What I end up doing is manually writing to pipe via So to facilitate my usecase, using an |
What about foreach ($process ....)? |
That appears to flush the write buffer, but never times out since timeout is never checked (this feels like a bug). Additionally, for my usecase I need to do other things besides only wait on output from process (ie the stream_select() case describe in other issue). |
To sum it up, the iterator input would work if there was a way to call |
Not sure stream_select fits into the component's scope. You may need to use proc_open directly, or use an abstraction provided by an async loop (e.g. ReactPHP) |
|
Instead of always closing the input pipe after exhausting the input buffer or
resource leave the input pipe open.