Re: Additions to PHP_Compat

From: Date: Wed, 26 May 2004 16:47:51 +0000
Subject: Re: Additions to PHP_Compat
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-29706@lists.php.net to get a copy of this message
On Wed, 26 May 2004 18:09:30 +0200, Michael Wallner wrote: > Hi Stefan Neufeind, you wrote: >>> Could these be added to PHP_Compat? >>> >>> if (!defined('STDIN')) { >>> define('STDIN', fopen('php://stdin', 'r')); >>> } >>> --- >>> if (!defined('STDOUT')) { >>> define('STDOUT', fopen('php://stdout', 'w')); >>> } >>> --- >>> if (!defined('STDERR')) { >>> define('STDERR', fopen('php://stderr', 'w')); >>> } >> >> If you use it in a program that e.g. does multiple writes to >> STDOUT, >> am I wrong that this would open the file again and again for each >> of the output-calls, resulting in many open files and never (until >> script end) closing any of these? Or do these calls always return >> the same handler to the stdout etc. (not tested)? > > I hope I got you right: > Once STDIN is defined it won't step into the if > condition any more, so php://stdin etc. is only > opened once. I think Stefan's worries have some ground... each time I *use* the constant STDIN, a fopen call will be issued (is it correct?). I never tried something like that, but the definition above looks more like a C macro than a define... What about: =========== if (!defined('STDIN')) { $_stdin = fopen('php://stdin', 'r'); define('STDIN', &$_stdin); } =========== of course it is absolutely untested, but it should give an idea of what Stefan was trying to say and a possible solution (?). When I use the STDIN constant, I want THE pointer back, not a NEW pointer each time... HTH -- Lorenzo Alberton http://pear.php.net/user/quipo

« previous php.pear.dev (#29706) next »