proc_open method takes an array or a string as first parameter
mho22 opened this issue · 4 comments
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.
sleep( 1 )seems to be mandatory, it doesn't work without setting it afterproc_open. Any dependency usingproc_open()won't work initially without addingsleep( 1 )after theproc_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:
wordpress-playground/packages/php-wasm/compile/php/proc_open7.4.c
Lines 602 to 609 in 93f2fbc
wordpress-playground/packages/php-wasm/compile/php/proc_open7.0.c
Lines 692 to 699 in 93f2fbc
Lack of support for an array $command can also be likely traced to that call.
@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?