Re: output buffering in CLI script.

From: Date: Thu, 28 Feb 2008 12:41:42 +0000
Subject: Re: output buffering in CLI script.
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-270548@lists.php.net to get a copy of this message
On 28 Feb 2008, at 12:29, Jochem Maas wrote:
Stuart Dallas schreef:
On 28 Feb 2008, at 11:52, Stut wrote:
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.
This works... ----<test.php>---- #!/usr/bin/php <?php echo "arse\n"; echo Inc('testinc.php'); function & Inc($f) { ob_start(); @include($f); $content = ob_get_contents(); ob_end_clean(); if (substr($content, 0, 2) == '#!') { $content = substr($content, strpos($content, "\n")+1); } return $content; } ----</test.php>---- ----<testinc.php>---- #!/usr/bin/php <?php echo "testinc\n"; ----</testinc.php>---- ----<output>---- Stut@Giles:~$ ./test.php arse testinc ----</output>---- -Stut -- http://stut.net/

« previous php.general (#270548) next »