Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68900 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6599 invoked from network); 5 Sep 2013 19:11:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Sep 2013 19:11:00 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.220.53 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.220.53 mail-pa0-f53.google.com Received: from [209.85.220.53] ([209.85.220.53:45323] helo=mail-pa0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 34/C0-23676-047D8225 for ; Thu, 05 Sep 2013 15:10:57 -0400 Received: by mail-pa0-f53.google.com with SMTP id lb1so2293322pab.40 for ; Thu, 05 Sep 2013 12:10:54 -0700 (PDT) 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=cnQTO0e3VmLmpDE3PZm1PWJW9hvAFNDHdc0VEKDmiYg=; b=deqVFbq79cElEkcGp+dd6JqWbWbdhxFOzD6DRvti254m2aXZICI8zN9NFU1mjGAsA5 4Pee+aCg+G7PKqUX0g2wMDg9xl0IZQmDel/yV57LRdeUFKZzFTwfNGUYIDB0lGru3XW6 Mw6oBxbDuT5Lb95oRkT+/sLHxyvgOEF+ne5EEwife1klO9f0+t6ydMsa/mdVQWQ3AqvY 7M3wc0s/fdYPOJdP+fCcjT6eKCs3LzQoMygvaeOAaLWrKm4NHBQOomB4Mcw2GgLF+617 K/eqAi/0UZZ5aM/LkoyZYn3K488OtTdKYRb/YxWobV93imauyQ0A4kMwrcE9E5rI1EdE hYSA== X-Gm-Message-State: ALoCoQmxKVHyQ7xwUutUoMysNJWENL51RRjDhCOg8B0LIc4XJRLACFfoMgo7AY8ZUOlO+fYTJYV0 MIME-Version: 1.0 X-Received: by 10.66.216.129 with SMTP id oq1mr11095596pac.75.1378408253983; Thu, 05 Sep 2013 12:10:53 -0700 (PDT) Sender: php@golemon.com Received: by 10.70.24.33 with HTTP; Thu, 5 Sep 2013 12:10:53 -0700 (PDT) X-Originating-IP: [173.252.71.189] In-Reply-To: References: Date: Thu, 5 Sep 2013 12:10:53 -0700 X-Google-Sender-Auth: 98PD3xRpuEBKhIMflKN7pjgaCa4 Message-ID: To: Daniel Lowrey , wez@php.net Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b5d954955c09904e5a7ae69 Subject: Re: [PHP-DEV] New function: stream_socket_listen() From: pollita@php.net (Sara Golemon) --047d7b5d954955c09904e5a7ae69 Content-Type: text/plain; charset=ISO-8859-1 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 > --047d7b5d954955c09904e5a7ae69--