Skip to content
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

Causes issues passing descriptors to subprocesses #43

Open
donatj opened this issue Oct 29, 2023 · 5 comments
Open

Causes issues passing descriptors to subprocesses #43

donatj opened this issue Oct 29, 2023 · 5 comments

Comments

@donatj
Copy link

donatj commented Oct 29, 2023

I had an issue reported to my package donatj/mock-webserver that turned out to be caused by this package.

donatj/mock-webserver#59 (comment)

After poking @sigma-z's example a bit, I've determined there's some sort of problem with this using this library AND generating file descriptors that can be passed to sub processes with proc_open.

I've boiled an example of the problem down to:

<?php

require __DIR__ . '/vendor/autoload.php';

DG\BypassFinals::enable();

$stdin   = fopen('php://stdin', 'rb');
$stdoutf = tempnam(sys_get_temp_dir(), 'dgb.test');

$descriptorSpec = [
	0 => $stdin,
	1 => [ 'file', $stdoutf, 'a' ],
];

$fullCmd = 'echo "This should come LAST in the output"';
$process = proc_open($fullCmd, $descriptorSpec, $pipes);

sleep(1);

echo "=== Text should come AFTER this line not before... reading from {$stdoutf} ===\n";
echo file_get_contents($stdoutf);

If you run this, you get something like

dup2: Bad file descriptor
This should come LAST in the output
=== Text should come AFTER this line not before... reading from <path> ===

If you comment out the line DG\BypassFinals::enable(); though you get the expected

=== Text should come AFTER this line not before... reading from /private/var/folders/dr/cpm01_51333c1px2yzc8qr9xq1kth0/T/dgb.testx1XyaY ===
This should come LAST in the output

It's failing to either create or pass the file descriptor to the subprocess.

I seem to be able to solve it on my site by replacing the line

	1 => [ 'file', $stdoutf, 'a' ],

with

	1 => fopen($stdoutf, 'wb'),

and I very well might do that but I still think this likely calls for some investigation

@dg
Copy link
Owner

dg commented Oct 29, 2023

Thanks for the detailed description. The stream functionality is magic for me, so I don't quite know what to do with it, just experimenting. Could you verify that this solves the problem? 2cb1b3c

@sigma-z
Copy link

sigma-z commented Oct 30, 2023

@dg I checked your fix and cannot confirm that it works. The error stays the same. :(

@dg
Copy link
Owner

dg commented Nov 5, 2023

I have no idea what to do…

@sigma-z
Copy link

sigma-z commented Nov 6, 2023

@dg I am sorry. I tried to debug the code, but could not find anything of help. Maybe it is a bug in PHP itself. I am not deep in the php stream wrapper functionality and can not help here. :(

@dg
Copy link
Owner

dg commented Nov 19, 2023

I think the problem is the missing implementation of NativeWrapper::stream_cast(). But I have no idea how to implement it. And I couldn't find any documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants