Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91974 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63735 invoked from network); 28 Mar 2016 02:58:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Mar 2016 02:58:13 -0000 Authentication-Results: pb1.pair.com smtp.mail=grzegorz129@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=grzegorz129@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.54 as permitted sender) X-PHP-List-Original-Sender: grzegorz129@gmail.com X-Host-Fingerprint: 209.85.218.54 mail-oi0-f54.google.com Received: from [209.85.218.54] ([209.85.218.54:35684] helo=mail-oi0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8A/79-03797-2CD98F65 for ; Sun, 27 Mar 2016 21:58:11 -0500 Received: by mail-oi0-f54.google.com with SMTP id h6so100298023oia.2 for ; Sun, 27 Mar 2016 19:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=9DIV0CV2VP7VV5MpqM6mL7Urnh/UlfeR7rceUB8F9ys=; b=NsCWHWIALD7xZwJ/V3daY4PdxB4ChH/4+LOY+m+GNrIa6yyNidqn0dswbwt1plxh6K Dt4lgaddZH/q5k/SgtEct+7cQ3OoN8iM9RUBK7U6N5/zc894850NgKWRcFLm5ZbF0Cfv 1s7kOenrzFm1PkJyHZ6RWMnmJHmy/ZEKxW70v49XHn1L664w6jA/tlDrTJS+9wFxXGio 1/qFohdW9qAe5gYIlIouOyyKF4Iy6AdOUCxaCo+bWX0QastRvrg0gjUHQKUj8yoYM++W IWTCVznqxRA/7VqSfMTopFJ+W9mOZHW74Z9sEV4p6ietcSRawEo5+WjSW5iiA5hovQpo UY9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=9DIV0CV2VP7VV5MpqM6mL7Urnh/UlfeR7rceUB8F9ys=; b=FV031EPdD6RLVbIArp5BHByN/voda4IHLJT0hXdVAup5K3f4xVF9piNzdsCNnZMgXL hLfF5wZQH0pImAyb8JO2hsQIq4xNaXtsY+BOU3wmiaoHAIJZyXwICY1O0im3AXDtj/ia hIaCxx8m9O7Tx6ecRWTwb8N79LdGIAVi3uZ3gLnPLnEMhF5jvq6xV8mk98KcUqsqkdkn CjgOHyI0FTaZx2egfcfFjFrnaa5ZhIii1Kqei58fcXgxIMiIB8hEx7byhnpxxwNcVDHN FsfN8RMK0trPFFODWLujbp/XWD1zbhbRLdxXTtefgfclSbyUUb+W4jLDRAuYmoyRVdjp /SZw== X-Gm-Message-State: AD7BkJJM9vDvQq7MkuIIRGZfJDnBKkaY3IkkEYHVyiNAi2dqBE3QhhPuUzNNcobZGoLNeNRRH1CM30PZ8IeeqQ== X-Received: by 10.157.11.130 with SMTP id 2mr12004776oth.41.1459133887593; Sun, 27 Mar 2016 19:58:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.157.29.233 with HTTP; Sun, 27 Mar 2016 19:57:48 -0700 (PDT) Date: Sun, 27 Mar 2016 21:57:48 -0500 Message-ID: To: PHP internals list Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Handling "Bad file descriptor" during stream_select() From: grzegorz129@gmail.com (Grzegorz Zdanowski) Hello! During refactoring of one of my server projects written in PHP I was curious what PHP will do if one of FDs given to stream_select() will gone away. Of course by =E2=80=9Egone away=E2=80=9C I mean some underlying error like forceful close of FD and not a standard disconnection of the client. I did some tests, read documentation for select() call, dig into both kernel & PHP sources and I came to conclusion that there=E2=80=99s no way to cleanly recover fro= m stream_select() error :( It's also worth to mention PHP displays E_WARNING with error, but there's no clean way to determine actual error. I wrote simple test code: http://pastebin.com/6ws1xp5q After running it one of it's sockets need to be killed. The easiest way is to use gdb on linux: 1. gdb -p PID 2. call close(3) //it will kill listener 3. q 4. y After such sequence stream_select() will return false and all arrays will stay unmodified. Also as I mentioned before "PHP Warning: stream_select(): unable to select [9]: Bad file descriptor (max_fd=3D4)" will be triggered. I tried is_resource(), fread(), stream_get_meta_data(), feof() - none of them are giving me any clues which socket errored. Killing whole server on single socket error is not an option for me. Is there any (even crazy) way to determine which socket is considered bad? p.s. I found similar problem regarding C on SO, but they didn't found a good solution: http://stackoverflow.com/questions/12838041/method-to-handle-bad-file-descr= iptor-error --- Greg 'aka kiler129