Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52095 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62944 invoked from network); 30 Apr 2011 13:26:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Apr 2011 13:26:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.21 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.21 smtp1.ist.utl.pt Linux 2.6 Received: from [193.136.128.21] ([193.136.128.21:57449] helo=smtp1.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E2/98-10915-A1E0CBD4 for ; Sat, 30 Apr 2011 09:26:51 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.ist.utl.pt (Postfix) with ESMTP id D8A937000427 for ; Sat, 30 Apr 2011 14:26:46 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp1.ist.utl.pt ([127.0.0.1]) by localhost (smtp1.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id uKD2V0aWtA4e for ; Sat, 30 Apr 2011 14:26:46 +0100 (WEST) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 8DE7D70004A6 for ; Sat, 30 Apr 2011 14:26:46 +0100 (WEST) Received: from cataphract (a95-93-59-195.cpe.netcabo.pt [95.93.59.195]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 6E23F2007323 for ; Sat, 30 Apr 2011 14:26:46 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: Date: Sat, 30 Apr 2011 14:26:23 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_IST?= Message-ID: In-Reply-To: User-Agent: Opera Mail/11.10 (Win32) Subject: Re: [PHP-DEV] adding low level file handling stuff From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Sat, 30 Apr 2011 13:04:12 +0100, Ferenc Kovacs wrote: > recently I found a nice blogpost about how to properly daemonize a php > daemon: > http://andytson.com/blog/2010/05/daemonising-a-php-cli-script-on-a-posix-system/ > I've noticed in this article, that you can replace/redirect the > STDIN/STDOUT/STDERR from inside of your script, you have to close them, > and open in the correct order. > It works (at least on linux), because the opened files will have the > 1,2,3 FDs, because the OS assign the lowest available FD, which will > happen to be the required ones. > > [...] > So to correctly address this, one would need a way to get the FD for a > given fp and to be able to explicitly set the FD for an fp. > The required C methods for this would be the fileno and dup2. > > I've started to look around, that maybe there are existing > functions/extensions to make this work. > I've found that with 5.3.6 one can open arbitrary FDs thanks to Gustavo: > http://bugs.php.net/bug.php?id=53465 > this is the equivalent of fdopen, which was requested by Dennis Hotson > http://marc.info/?t=126854891300001&r=1&w=2 and he did implement that > https://github.com/dhotson/fdopen-php (+1 for adding fdopen also, the > stream based solution isn't obvious and easy to spot) > > But this doesn't help this problem. > > [...] > I would like to know, that why do these methods lacks (just nobody needed > them, or maybe it was a decision to keep out such low level methods from > the core)? > and if someone would make those, what should be the best place to add. > > [...] I actually did consider adding support for an extended form of php://fd where one would specify the desired file descriptor: php://fd//. It would call dup2 instead of dup. However, I got into some trouble on shutdown because this could cause stdout to be closed ahead of time and then the output subsystem would cause either a segfault or a memory leak (can't recall). I didn't spend more than 20 minutes on this as it was not the problem I was trying to solve, so there's probably an easy solution. If you want to work on this, extending php://fd would likely be a good place. -- Gustavo Lopes