Re: output buffering in CLI script.

From: Date: Thu, 28 Feb 2008 12:22:46 +0000
Subject: Re: output buffering in CLI script.
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-270541@lists.php.net to get a copy of this message
Stut schreef:
On 28 Feb 2008, at 11:39, Jochem Maas wrote:
I can't seem to manage to buffer output (of an included file) in a CLI script, the following does not work:
                   // buffer output so we can avoid the shebang line being output (and strip it from the output we log)
                   $oldIFvalue = ini_set('implicit_flush', false);
                   ob_start();
                   if (!@include $script) {
                       ob_end_clean();
                   } else {
                       $output = explode("\n", ob_get_clean());
                       if ($output[0] && preg_match('%^#!\/%', $output[0]))
                           unset($output[0]);
                   }
                   ini_set('implicit_flush', $oldIFvalue);
the reason I'm wanting to do this is, primarily, in order to stop the shebang line that *may* be present in the included script from being output to stdout.
On my local machine here PHP does not output the shebang line. AFAIK it detects and strips it at the compilation phase. Have you tried it?
I have, I actually wrote the code assuming that the shebang line is ignored (as I had experienced and read about ages ago), I was surprised to see the shebang line output in the shell ... so I figured I'd just buffer and strip the line manually given that php decided to treat the shebang line as regular output when it's the first line of an *included* file ... but no joy on getting output buffering to work in the shell, STFW didn't do it for me either, so now I'm hassling you guys :-) obviously the shebang line doesn't get output if I run said script directly (or by using exec) ... and yes I need to be able to do it both ways :-)
-Stut


« previous php.general (#270541) next »