Use random bytes API for child process file descriptor#53
Conversation
There was a problem hiding this comment.
@CharlotteDunois Thanks for working on this and filing this PR, but the motivation is currently unclear to me, so perhaps you can help clarify.
What is this ID used for? It's my understanding that this is just an arbitrary identifier that needs to be unique at a given time so that two calls to open() do not assign the same ID? If I'm not mistaken, it seems to be save to reuse previous IDs once they are no longer in use.
It's my understanding that using random numbers as IDs here only reduces the probability of a clash and doesn't really address the underlying issue. As an alternative, how about simply appending to this list and just let PHP add incrementing IDs (for example https://github.com/clue/reactphp-mq/blob/master/src/Queue.php#L248,L250)? What do you think about this?
|
PHP does not re-use numeric integers. If we wanted to re-use IDs we'd have to make our own management for this. The only numeric key PHP re-uses is the |
This PR changes the file descriptor from the array size to random bytes. Compatibility is guaranteed through random_compat, although PHP5 support is running out in one month.
Using random bytes guarantees no clashing file descriptors, that means re-using and overwriting a currently active file descriptor.