[PHP_DEV] [RFC] Add file_descriptor() function

php.internals

Girgias

3 years ago
Hello internals, I would like to start the discussion about the "Add file_descriptor() function" RFC: https://wiki.php.net/rfc/file-descriptor-function This RFC proposes the addition of the file_descriptor() function to retrieve the underlying file descriptor of stream if it exists. This is useful when interacting with a USB device. Best regards, George P. Banyard

Bob Weinand

3 years ago
> Am 16.01.2023 um 16:01 schrieb G. P. B. <george.banyard@gmail.com>: > > Hello internals, > > I would like to start the discussion about the "Add file_descriptor() > function" RFC: > https://wiki.php.net/rfc/file-descriptor-function > > This RFC proposes the addition of the file_descriptor() function to > retrieve the underlying file descriptor of stream if it exists. This is > useful when interacting with a USB device. > > Best regards, > > George P. Banyard
Hey George, I like the idea. However two questions: Why is it its own function and not part of stream_get_meta_data()? (which you anyway want to check to ensure that it's the proper stream type) Why are all resources throwing a TypeError and not only resources which aren't streams? I could imagine calling that function to check whether the stream is in memory or backed by a fd for example. I'd propose to return a proper checkable value like -1 in that case. Thanks, Bob

Christoph Becker

3 years ago
On 16.01.2023 at 16:01, G. P. B. wrote:
> I would like to start the discussion about the "Add file_descriptor() > function" RFC: > https://wiki.php.net/rfc/file-descriptor-function > > This RFC proposes the addition of the file_descriptor() function to > retrieve the underlying file descriptor of stream if it exists. This is > useful when interacting with a USB device.
Thanks for the RFC! I wonder, though, what happens if the file descriptor is then manipulated directly, but the stream is accessed later. Probably, there's no way to keep the stream resource properly working in all cases. Isn't the DIO extension[1] already sufficient for such kind of low-level stuff? [1] <https://pecl.php.net/package/dio>
-- Christoph M. Becker

Tim Düsterhus

3 years ago
Hi On 1/16/23 16:01, G. P. B. wrote:
> useful when interacting with a USB device.
Can some example code be added to the RFC text for those who don't understand any French? Best regards Tim Düsterhus