WordPress/wordpress-playground

proc_open method takes an array or a string as first parameter

mho22 opened this issue · 4 comments

mho22 commented

I am trying out proc_open method and php.setSpawnHandler() to handle the unhandled proc_open by php-wasm and I found out several things :

$command in proc_open( $command, ... ) is array|string $command,.

If I add proc_open( [ "ls", "-a" ], ...) , I get only ls in my php.setSpawnHandler( command => ... ) callback.

It seems if I ommit a $descriptor_spec pointer in proc_open() :

$descriptor_spec = [
    1 => ['pipe', 'w'],
    2 => ['pipe', 'w']
];

instead of

$descriptor_spec = [
    0 => ['pipe', 'r'],
    1 => ['pipe', 'w'],
    2 => ['pipe', 'w']
];

I get an error. Even if this sounds valid in php.

  1. sleep( 1 ) seems to be mandatory, it doesn't work without setting it after proc_open. Any dependency using proc_open() won't work initially without adding sleep( 1 ) after the proc_open() call.

I would be glad to help more or dig deeper if i can help.

Hey @mho22! Thank you so much for reporting, this is great timing as I was exploring the mandatory sleep( 1 ) issue today. Here's where I got: #931. I won't be exploring this further for now so you're welcome to take over if you'd like to – I'll do what I can to support you!


As for the $descriptor_spec issue, it's probably related to the fact these two files use a hardcoded number of arguments:

js_open_process(
command,
descriptors[0].childend,
descriptors[1].childend,
descriptors[1].parentend,
descriptors[2].childend,
descriptors[2].parentend
);

js_open_process(
command,
descriptors[0].childend,
descriptors[1].childend,
descriptors[1].parentend,
descriptors[2].childend,
descriptors[2].parentend
);

Lack of support for an array $command can also be likely traced to that call.

mho22 commented

@adamziel Can I propose a pull request to allow having no specific descriptors in js_open_process in certain use cases? I currently have this use case:

$process = proc_open( [ [ 'stty', '-a' ], [ 1 => ['pipe', 'w'], 2 => ['pipe', 'w'] ], $pipes, null, null, [ 'suppress_errors' => true ] );

This should normally work correctly.

Can I attempt to make it work without altering the current behavior?

That would be fantastic @mho22! :)

Solved in #969