Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68902 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72329 invoked from network); 6 Sep 2013 05:15:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Sep 2013 05:15:10 -0000 Authentication-Results: pb1.pair.com header.from=wez@netevil.org; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=wez@netevil.org; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain netevil.org designates 209.85.212.171 as permitted sender) X-PHP-List-Original-Sender: wez@netevil.org X-Host-Fingerprint: 209.85.212.171 mail-wi0-f171.google.com Received: from [209.85.212.171] ([209.85.212.171:44102] helo=mail-wi0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0B/81-56379-DD469225 for ; Fri, 06 Sep 2013 01:15:10 -0400 Received: by mail-wi0-f171.google.com with SMTP id hm2so387857wib.4 for ; Thu, 05 Sep 2013 22:15:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netevil.org; s=google; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=RarNBmI2xhToH0DjZSM/ekcrbPSQw3M+zeM1PAPaL8s=; b=JitCKCsP6wewCMcZLaIt2RNGWV2RqG+LYZtPjbhKT1h4iLjdElaNKINDvsvaOlO8Lp BUSmKqt4FUZERUHYJG7mv/3JZqLB4dWCGJecFMouDMgWq8OHih6yKDAYCxae8lI5Wmad oY+emHZxLL8aru+l3LPfPGFemDUR979jJ/IAo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wezfurlong.org; s=google; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=RarNBmI2xhToH0DjZSM/ekcrbPSQw3M+zeM1PAPaL8s=; b=FXK6hUouJ1+FgTMIB479dSy3OovFlWmeLzsi82+A6WYfsDGwdhBKSNJyOUPA52WS8b 0HkIOna/KGlgKQyPF6VZGbO0CxTNBHeYutfPWhu49edmC+zsoOuraQ+zEUhDcm0o4naQ lvfZ9LfOLAObt1ZXDV9gRUuzIeF/LCi1tKDjc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=RarNBmI2xhToH0DjZSM/ekcrbPSQw3M+zeM1PAPaL8s=; b=e9M6uUodDlC8lT5vVaUMBI+w2bd6pHCCg4OzkBQIl7QNzBjK0V1cUvlUKBYQnRh+aw SjaW/1PGd+yN7w6HOHkzjbWAnEtTuJJ8FBNP1s1PK0tifiRoHLofcGzeChhDEVF/cBpF UvVg3tjVb0y/+5cgkTGIV1iQLTVuUf09qSrMnJ3a4Wd5+AxAjRr/HBP1PfyzsL8f67DB qpx1ZpiOAHkW/F2WhmZdQrU+ZVrNX2SLDb0ERhZnDwfj036LSNaqEO7VwitznbNHDF4M gzJW0DxuTWdefsR2p8E9aQL0acZq9bZcuxpaZ9b6lFlyRhNROBOmdNbtpM/Pb+QM0Dy5 tbNw== X-Gm-Message-State: ALoCoQlcusjw1yQPX3rA4HjygwiIZWjJFbKlZ32RrJBJULnbyD4oRMf2TGEj6/dJ7l4on/K5X7h+ MIME-Version: 1.0 X-Received: by 10.194.20.170 with SMTP id o10mr515275wje.4.1378444504954; Thu, 05 Sep 2013 22:15:04 -0700 (PDT) Sender: wez@netevil.org Received: by 10.194.16.105 with HTTP; Thu, 5 Sep 2013 22:15:04 -0700 (PDT) X-Originating-IP: [50.193.54.201] In-Reply-To: References: Date: Thu, 5 Sep 2013 22:15:04 -0700 X-Google-Sender-Auth: iFMLXT2yim0EExLAj_7xAkRHZX0 Message-ID: To: Daniel Lowrey Cc: "internals@lists.php.net" , Sara Golemon Content-Type: multipart/alternative; boundary=047d7b5d5c820f8e6104e5b01f2b Subject: Re: [PHP-DEV] New function: stream_socket_listen() From: wez@wezfurlong.org (Wez Furlong) --047d7b5d5c820f8e6104e5b01f2b Content-Type: text/plain; charset=ISO-8859-1 I'm not opposed to the idea; the reason that I didn't implement it initially is that I wanted something functional in the core (ext/sockets was often not available) and we didn't have "PHP Spirit" equivalents of the various and murky socket option setting APIs that are present in ext/sockets (it's not the most intuitive interface even for C developers). So we got an implementation that does what you want for most cases; bind and listen in one step. I won't block this patch, but it would be /really/ great if you could follow-on with a diff to allow setting the most commonly used socket options (plus SO_REUSEPORT, since you mentioned it) and also a function to allow setting CLOEXEC (perhaps stream_set_cloexec(bool)), which is something I wish I'd added back when I put this stuff together! You win super extra crazy bonus points for allowing something like this https://bitbucket.org/wez/couchshare/src/bcbf02e1a70d0dba86564480c63f5d6596658815/upnp-srv/couchshare.c?at=default for setting multicast options. Thanks! --Wez. On Thu, Sep 5, 2013 at 12:10 PM, Sara Golemon wrote: > Seems reasonable to me, but Wez should probably weigh in on it. I vaguely > recall a conversation with him when he first implemented stream_socket_*() > and a reason why listen wasn't in the API. > > -Sara > > > On Thu, Sep 5, 2013 at 10:30 AM, Daniel Lowrey wrote: > >> The stream socket functions are incredibly useful and obviate the need for >> the sockets extension for the vast majority of potential use-cases. >> However, it's currently it's not possible bind a socket and listen for >> connections in separate steps using stream_socket_server(). >> >> This _can_ be done with the aid of ext/sockets like so: >> >> $stream = stream_socket_server('tcp://0.0.0.0:0', $errno, $errstr, >> STREAM_SERVER_BIND); >> $sock = socket_import_stream($stream); >> socket_listen($sock); >> >> Why is this useful? Well, for example, binding to a port in the main >> process and then listening individually in child forks/threads trivializes >> scaling socket servers. By listening on the same bound socket in multiple >> processes you get the advantage of the OS distributing new client >> connections to the individual workers instead of routing them in userland. >> Additionally, newer linux kernel versions (3.9x) now support the >> SO_REUSEPORT socket option which only makes this functionality more >> attractive. Admittedly you still need ext/sockets to reap the benefits of >> SO_REUSEPORT, but this may not always be the case. >> >> My proposed patch adds a very simple function so that listening may be >> decoupled from binding without the need for ext/sockets: >> >> $stream = stream_socket_server('tcp://0.0.0.0:0', $errNo, $errStr, >> STREAM_SERVER_BIND); >> // do stuff, fork, etc. Then in the child process: >> stream_socket_listen($server); >> >> Existing functionality is not modified and there are no BC breaks. I.E. >> you >> can still bind + listen in a single step like before: >> >> $stream = stream_socket_server('tcp://0.0.0.0:0', $errNo, $errStr, >> STREAM_SERVER_BIND | STREAM_SERVER_LISTEN); >> >> This addition seemed a bit trivial for an RFC, so and I didn't bother >> hitting the wiki. The link to the relevant pull request follows. Any >> thoughts, comments and opinions are welcome: >> >> https://github.com/php/php-src/pull/431 >> > > --047d7b5d5c820f8e6104e5b01f2b--