-
Notifications
You must be signed in to change notification settings - Fork 32
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
Retrieve php resources from native code #36
Comments
TL;DR: Probably no. It doesn't really make sense to support this as a built-in part of FFI, but there are other ways to do this. Resources are too complex to provide any kind of (useful) generic support for them - they are essentially objects without a public API, wrapping arbitrary data structures up in an opaque ball of state. For any conceivable use case you would always need a lot of definitions on top in order to access the underlying data. However... The specific case you use as an example can (probably) already be handled with existing core PHP functionality. If you know the number of an fd, you can obtain a stream resource referencing it via the // Create a stream wrapping fd#1 - the mode is ignored as the descriptor already exists
$fp = fopen('php://fd/1', 'w');
// Usually fd#1 is stdout, so this will output to the console
fwrite($fp, 'Hello world'); ...unfortunately though, I'm not aware of any way to do the reverse of the code above, i.e. you can't get the fd number from an existing stream resource. There have been one or two occasions in the past where I have wanted this for something, so it might be worth adding some way to access that information - but again this would not be a matter for FFI, I would suggest something more along the lines of an extra element in the array returned by |
Hi, thanks for your answer. |
Hi,
let's say I want to use
open()
fromfcntl.h
If I load this into FFI:
int open(const char *pathname, int flags);
then php see the result as an integer, while it is a file descriptor.
Am I wrong?
Is there a way to handle file descriptors?
The text was updated successfully, but these errors were encountered: