Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91981 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32076 invoked from network); 29 Mar 2016 00:03:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Mar 2016 00:03:33 -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.48 as permitted sender) X-PHP-List-Original-Sender: grzegorz129@gmail.com X-Host-Fingerprint: 209.85.218.48 mail-oi0-f48.google.com Received: from [209.85.218.48] ([209.85.218.48:33170] helo=mail-oi0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 26/00-31598-356C9F65 for ; Mon, 28 Mar 2016 19:03:32 -0500 Received: by mail-oi0-f48.google.com with SMTP id d205so192164002oia.0 for ; Mon, 28 Mar 2016 17:03:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=CjmpdykM1sLFZzBN/rK0d1SScZzZb+3bS/iM7bmNqZU=; b=LLHAs2sU3U26uST3ziqj5PnE3dwOnWpBfwQ40DRId/M2mMoy81sBoeIoV9NGjBO1VV QPqlrxM5XAPhGONo8spKe8zGCVfrErZWY+PCCp9hVCUtZxkOzeKCF8g6u3Yeftej74dE wvpZkjmySBLsZ6wbqMnPFNjh3vhr+b3TzAgvFMyFoP4IU2kmCTowQ8hHdWMU+cJOb2lF nj4P5AkbbjLD7Zg+OYXoiXBTKPgIMJPFdFui1JoDbOWBrvlsNiAijB2CasYkhyCOCcye GWxrDzh/jO445Qkf+lRjVqvgdj99qMLFvTOAO0grmndYdRSFEtqMMyiNyhPXlALKD4Pq B9+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=CjmpdykM1sLFZzBN/rK0d1SScZzZb+3bS/iM7bmNqZU=; b=KLtbM65WoPepABALGWguHSVxc4dCcaUpRavDWrwqTHNydxk217Bu+yN4D305DGcZgi yQH+7+TjottP8fO1MAyuXYkByqri/5GcKIqPYghYhfAbiM4GZQQkDp4a289Hb4upoCRY lkNRHoH5AXUNqw7bA5bYTuH+ZjQN73bv2WbDk36pvGeCvF12y9x52dRR8g438dISHmp5 zeb4Y5vFnQdGxuPrgXYaRpdfQJS7u+ya7l9IyKbhe3F4MWXiRmx1ygSn2MOHeGyDg/F8 ljXk/bvP7jAcSekiCbZma9rFPJc2hnxLRfaY3SHw/sla18NmMMastLR1SNt28L16LLIG HNNw== X-Gm-Message-State: AD7BkJJrA6/g0T4hr2HATWHEtTsiOyE3U6KEZFG13r5pq84OfWmxI6nVvDD7oolgnfvoHV/Md6Ljc97v+Nom7Q== X-Received: by 10.157.11.130 with SMTP id 2mr14516877oth.41.1459209809385; Mon, 28 Mar 2016 17:03:29 -0700 (PDT) MIME-Version: 1.0 Received: by 10.157.29.233 with HTTP; Mon, 28 Mar 2016 17:03:09 -0700 (PDT) In-Reply-To: References: Date: Mon, 28 Mar 2016 19:03:09 -0500 Message-ID: To: Dan Ackroyd Cc: PHP internals list Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Handling "Bad file descriptor" during stream_select() From: grzegorz129@gmail.com (Grzegorz Zdanowski) 2016-03-28 11:19 GMT-05:00 Dan Ackroyd : > On 28 March 2016 at 02:57, Grzegorz Zdanowski wro= te: >> 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. > > What problem exactly are you trying to solve, and do you have a way of > showing the problem that isn't just what looks like a programming > mistake? You're missing one point - the native file descriptor living inside a kernel and somewhat managed by PHP C code can change it's state independently from PHP knowledg= e. The problem is stream resource is only an loosely representation of native FD, not an actual file descriptor. TBH I don't know any way to damage the actual FD by programmer mistake in P= HP. I came across the problem in real environment in two cases: 1. Socket was listening with some specific IP and network card gone away. Every call to stream_select() produced situation described in OP and send the code into dead-loop. 2. Using hardware-dependent socket (like ttys to USB<>RS232 converters) you= can trigger such error by simply disconnecting the USB cord (not always, because some drivers will just trigger EOF on socket and close it gracefully). > e.g. The following code works fine. The file being closed doesn't > affect the filehandle > > $fileHandle =3D fopen('foo.txt', 'r+'); > unlink('foo.txt'); > $data =3D fread($fileHandle, 20); It's perfectly understandable - files have nothing to do with file descriptors opened for them. > The following code doesn't work fine. The filehandle being closed, > surprisingly enough, makes it not usable any more: > > $fileHandle =3D fopen('foo.txt', 'r+'); > fclose($fileHandle); > $data =3D fread($fileHandle, 20); Yes, that's true - after you call fclose() PHP gracefully closes the socket and marks the memory, so $fileHandle will no longer be a valid stream resource. > So I don't understand what problem you're trying to analyze, other > than closed file descriptors are closed. If the socket was properly closed there's no discussion - you deal with thousand times a day, but the problem comes when the underlying FD will gone away. Actually I found in C you can just call fcntl(FD, F_GETFD) and you'll get -1 if given FD is no longer valid FD. In PHP there's no way to do it - that's my problem. --- Greg 'aka kiler129