Re: output buffering in CLI script.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

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?

Hang on, ignore that. You're including the file, not running it on the CLI.

What do you mean when you say it doesn't work? Do you mean you get no output?

I mean that the shebang line at the top of the included file is output
to stdout even when I turn on output buffering on prior to including the file.

nothing else is output but that's because the script doesn't generate any further
output - it logs everything instead - and I know it runs because the relevant lines
appear in the relevant log file.


I suggest you remove the @ at the start of the include while developing it. Or alternatively spit something out after you call ob_end_clean so you know it couldn't include the file.

the @ is niether here nor there with regard to the problem I have, well more
of an annoyance - nobody is going get hurt by some spurious output to stdout but
it looks messy.

just to clarify - I need to be able to run the script directly (as an executable) and
be able to include it within another script ... so the shebang line is needed
(well I could hack around it with a wrapper script to use directly on the command line
or run it using /usr/bin/php foo.php ... but I don't find either of those satisfactory)




-Stut


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux