RE: [PHP] output buffering in CLI script.
| From: | Andrés Robinet | Date: | Thu, 28 Feb 2008 11:52:23 +0000 |
| Subject: | RE: [PHP] output buffering in CLI script. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-270534@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Jochem Maas [mailto:jochem@iamjochem.com]
> Sent: Thursday, February 28, 2008 6:39 AM
> To: [php] PHP General List
> Subject: [PHP] output buffering in CLI script.
>
> hi there,
>
> 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.
>
> --
Aren't you deleting the output when you do ob_get_clean?
Meaning, you are missing an echo of the captured buffer, like:
$output = explode("\n", ob_get_clean());
if ($output[0] && preg_match('%^#!\/%', $output[0]))
unset($output[0]);
echo join("\n", $output); // You need to echo this, since you lost your buffer
by doing ob_get_clean
Regards,
Rob
Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308 |
TEL 954-607-4207 | FAX 954-337-2695 |
Email: info@bestplace.net | MSN Chat: best@bestplace.net | SKYPE: bestplace |
Web: bestplace.biz | Web: seo-diy.com