Re: Getting fd from stream
| From: | Sara Golemon | Date: | Thu, 06 Jul 2017 15:20:25 +0000 |
| Subject: | Re: Getting fd from stream | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-99800@lists.php.net to get a copy of this message | ||
On Thu, Jul 6, 2017 at 10:53 AM, Kalle Sommer Nielsen <kalle@php.net> wrote:
> 2017-07-06 11:12 GMT+02:00 Martijn van Duren <php@list.imperialat.at>:
>> I have an (exotic) case where I need to be able to get the
>> filedescriptor from a previously opened stream (via stream_socket_pair)
>> to hand over to the child process, which needs to reexecute.
>>
>
"hand over to a child process"
Child as in pcntl_fork()? Or a subprocess via exec() et. al.?
For the former, the variable should (I think) carry over.
For the latter, the stream number is going to be a meaningless value
to the subprocess. ((e.g. stdin (fd=0) for the parent is a different
source than stdin for the child, despite being the same number)).
I'm not sure of your exact use case, but you might be able to use
proc_open to spawn the child and supply the socket in the descriptor
spec which will (I think, iirc) bind the internal socket to a new pipe
between the parent and child. Though it's possible you'll need to
maintain a proxy loop in the parent.
40% of the above is guesswork and conjecture, but maybe it'll spawn
the right question.
-Sara