Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52133 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15242 invoked from network); 6 May 2011 23:48:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 May 2011 23:48:33 -0000 Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.215.170 mail-ey0-f170.google.com Received: from [209.85.215.170] ([209.85.215.170:39039] helo=mail-ey0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 03/00-14528-DC884CD4 for ; Fri, 06 May 2011 19:48:30 -0400 Received: by eyf5 with SMTP id 5so1117397eyf.29 for ; Fri, 06 May 2011 16:48:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=dAD1R7zl7/Sy9DWEIyi71pZC+izqlBzjhgGun/oFvh0=; b=HMvvGZGzz482t9Rb3NsvyxsGoxhTEHNJSmEnAlSiADz3z12wkEojtBHJy5w1yj57TA UkY4R8ZCOUP8WC1NggIa/TSeYsEjfw8uzYvKgBoT9xVcffmRm4NSXNBE8psKuZPxsevK FbCYxMp5JkbMqtV0OaS8VWGifgH1XUFHTF7x8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=NHOWXhdq8L6kFrGf38UV+8dJi7IAxME5ScTtbgcq4Yseuf9zQ1F2LNP/FyvE4Qhz1T gcHid0ynR4tMugWkx+X6/TTUPi9jYZ2dNGPoWI0mqJoLDeUJt1RgqRwF6A155U6uRd+5 VDCguFfxDLfRoJH2cetVxKlUfjl32NJw7jokI= MIME-Version: 1.0 Received: by 10.14.2.31 with SMTP id 31mr2161652eee.167.1304725240080; Fri, 06 May 2011 16:40:40 -0700 (PDT) Sender: tyra3l@gmail.com Received: by 10.14.127.79 with HTTP; Fri, 6 May 2011 16:40:40 -0700 (PDT) In-Reply-To: References: Date: Sat, 7 May 2011 01:40:40 +0200 X-Google-Sender-Auth: g9g4OAtM5ye6iV-P2JIWNxvviaE Message-ID: To: Gustavo Lopes Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] adding low level file handling stuff From: info@tyrael.hu (Ferenc Kovacs) On Thu, May 5, 2011 at 2:30 AM, Ferenc Kovacs wrote: > > > On Sat, Apr 30, 2011 at 5:23 PM, Ferenc Kovacs wrote: >>> >>> I actually did consider adding support for an extended form of php://fd >>> where one would specify the desired file descriptor: php://fd/= />> 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 c= ause >>> 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, extendi= ng >>> php://fd would likely be a good place. >>> >>> -- >>> Gustavo Lopes >>> >>> -- >>> PHP Internals - PHP Runtime Development Mailing List >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >> >> thanks Gustavo. >> as you check my mail, I also mentioned using dup2 instead of dup, for >> obvious reasons. >> adding dup2 support for the php://fd stream would be better than the >> current situation, but I can't see why are we trying to force everything >> into that. >> I mean everything on the=C2=A0http://www.php.net/manual/en/wrappers.php= =C2=A0can be >> achived through a function also. >> there are some case when you can save a couple of lines of code with the >> wrappers and with=C2=A0http://www.php.net/manual/en/context.http.php=C2= =A0but there is >> no method for opening FDs or the dup2 that you mentioned. >> I think that it would be more consistent with the rest of the language, >> and one would more likely to find fdopen than fopen('php://fd/1'); in th= e >> documentation. >> closing the stdout without reopening also caused problems for me in case >> of an error happens, but this shouldn't happen if you properly reopen it= , so >> I would be=C2=A0interested=C2=A0what exactly happened there. >> Tyrael > > I put together the fileno, fdopen, dup2, fclose stuff as a pecl > extension(called fildes), the sourcecode available here: > https://github.com/Tyrael/php-fildes > with this, you can do something like this: > $stdout_fd_orig =3D fildes_fileno(STDOUT); > fclose(STDOUT); > $stdout =3D fopen("out.log", "a"); > $fd_tmp =3D fildes_fileno($stdout); > $stdout_fd =3D fildes_dup2($fd_tmp, $stdout_fd_orig); > if($stdout_fd !=3D $fd_tmp){ > =C2=A0 =C2=A0 =C2=A0 =C2=A0 fildes_close($fd_tmp); > } > echo "Hello world!"; // this goes to out.log > I'm really a novice in C, so any feedback welcome. > particularly > here=C2=A0https://github.com/Tyrael/php-fildes/blob/master/fildes.c#L211 > Tyrael as somebody pointed out, the example could be simplified as: