process icon indicating copy to clipboard operation
process copied to clipboard

More pipes?

Open LacticWhale opened this issue 1 year ago • 4 comments

Is there a way to open more pipes? In normal PHP I can use proc_open to do something like this:

$descriptors = array(
    0 => array("pipe", "r"),  // STDIN
    1 => array("pipe", "w"),  // STDOUT
    2 => array("pipe", "w"),  // STDERR
    3 => array("pipe", "w"),  // DATA
);
$proc = proc_open("data_handler", $descriptors, $pipes, "../../../submodules/data_handler/program");
foreach ($inputs as $input) 
    fwrite($pipes[0], $input.PHP_EOL);
fclose($pipes[0]);

$data   = stream_get_contents($pipes[3]); fclose($pipes[3]);
$stderr = stream_get_contents($pipes[2]); fclose($pipes[2]);
$stdout = stream_get_contents($pipes[1]); fclose($pipes[1]);
$exitCode = proc_close($proc);

I couldn't find any documentation on this.

LacticWhale avatar Sep 30 '24 16:09 LacticWhale

Currently this is not supported. What are you trying to do?

kelunik avatar Oct 01 '24 05:10 kelunik

What are you trying to do?

I just had a program which used stdout for debug info and an additional pipe for data transfer. It's not a big problem I can move info to stderr and use stdout for data. But it would be nice to have support for this in the future.

LacticWhale avatar Oct 01 '24 07:10 LacticWhale

If you control both sides, you might find the IPC API of amphp/parallel helpful: https://github.com/amphp/parallel?tab=readme-ov-file#ipc

kelunik avatar Oct 01 '24 19:10 kelunik

I use it to run programs written in different languages (python, dart). I just did:

list($command, $id, $data) = explode(':', $chunk);

Instead of using different pipes. I guess I could have done this from begining.

But still I think it might be useful to get support for pipes in future.

LacticWhale avatar Oct 01 '24 21:10 LacticWhale