Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52134 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15544 invoked from network); 6 May 2011 23:48:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 May 2011 23:48:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass; domainkeys=bad 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 0D/00-14528-ED884CD4 for ; Fri, 06 May 2011 19:48:48 -0400 Received: by mail-ey0-f170.google.com with SMTP id 5so1117397eyf.29 for ; Fri, 06 May 2011 16:48:46 -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=998u0arOMWTxb/ZluWKvpqj6u9IykNGPq26yKkxwseo=; b=AVt7GoYu/oTrS8KR3Vde19rrtc/9nTQuVTrRv6zspFWo+JlDKVYpYPCZkTBB2tQanW OogXZsaec7iQPR6TFIdt8bGycFxtbjd/GCdwRRiP9ZulXObLB6SaxTsP1XgKd7d9EdPw S1BHh7vFhgUUz37Iusx10LSSPPFmfE2gNGe1I= 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=dTgFGOs/KYPPseBFFazX7nx3KQn88CdU6mT1VtRLaDBBtuosr2O9xlZ8V+2mWKMmMr Vl2jFUIBxqQH7+qkN4UnO7/a+9yGweFc+8vclAIWzu9fOtMHQBkJGpI9WC6Qyqu1+Xim DIw9c0ioiZyHnrAfyeo7/kqX10LM58QbLosvw= MIME-Version: 1.0 Received: by 10.14.148.67 with SMTP id u43mr2181756eej.7.1304725726206; Fri, 06 May 2011 16:48:46 -0700 (PDT) Sender: tyra3l@gmail.com Received: by 10.14.127.79 with HTTP; Fri, 6 May 2011 16:48:46 -0700 (PDT) In-Reply-To: References: Date: Sat, 7 May 2011 01:48:46 +0200 X-Google-Sender-Auth: DY7-DCRCI1kTVRPudARWbME0iY4 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 Sat, May 7, 2011 at 1:40 AM, Ferenc Kovacs wrote: > 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://f= d >>>> 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 = 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, extend= ing >>>> 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 everythin= g >>> 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 th= e >>> 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 t= he >>> documentation. >>> closing the stdout without reopening also caused problems for me in cas= e >>> of an error happens, but this shouldn't happen if you properly reopen i= t, 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: > $stdout =3D fopen("out.log", "a"); > $tmp_fd =3D fildes_fileno($stdout); > if($tmp_fd, fildes_fileno(STDOUT))<0){ > =C2=A0 =C2=A0fwrite(STDERR, "dup2 failed"); > =C2=A0 =C2=A0exit; > } > fildes_close($tmp_fd); > echo "Hello world!"; // this goes to out.log > > Could somebody review the source? as I mentioned in my previous email > I had some problem here: > https://github.com/Tyrael/php-fildes/blob/master/fildes.c#L211 > > if I define the second argument as int, the first argument will be always= 0. > I have no idea whats going there. > > Tyrael > and I forgot to ask the most important thing: what do you think about the feature itself? I would really like to have it in the core, but I think it would be better to have this as functions, than adding more stream magic. I'm not sure where would this functions fit the best. 1, it could be added to the filesystem functions (we already have some which are only supported on some systems) 2, it could be added to the posix functions (would be logical) 3, it could be added as stream stuff (Gustavo supports this imo) 4, it could be added to the dio pecl extension (could fit in there, but it's not in the core, and the package doesn't seem much alive) 5, it could be added to pecl as a different extension (bad idea, imo) so, what do you think? Tyrael