Re: Getting fd from stream

From: Date: Fri, 07 Jul 2017 15:04:02 +0000
Subject: Re: Getting fd from stream
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-99810@lists.php.net to get a copy of this message
On 07/07/17 16:38, Sara Golemon wrote: > On Fri, Jul 7, 2017 at 10:04 AM, Martijn van Duren > <php@list.imperialat.at> wrote: >> My use case is to set up a cluster of processes each with their own task >> and permission sets. These processes need to be able to communicate with >> each other over socket pairs, not just between the parent and the child, >> but also between children. >> > Sounds like you're describing unix domain sockets (or NamedPipes if > you're on Windows). > > -Sara > Yes, although tcp/ip are also possible with stream_socket_pair. The point is, regardless of unix - or tcp sockets, they still have an underlying file descriptor, which I need to specify to the child, so that they can start using it. Ergo, I need to find a way to export this from the stream into PHP. To put it in code: <?php $sp = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0); echo (int) $sp[0]."\n"; ?> This returns 4 (the object id), instead of 3 (the fd). If I could get the fd, I could turn this into something like: <?php $sp = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0); switch (pcntl_fork()) { case -1: exit(255); case 0: fclose($sp[1]); pcntl_exec("/usr/local/libexec/whatever", ["-i", (int) $sp[0]]); default: fclose($sp[0]); do_parent_code(); } ?> Where whatever can be anything from a PHP-script to a C-compiled binary.

« previous php.internals (#99810) next »