Stuart Dallas schreef:
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...
indeed ... I tested it and it works on my server too. my code is no different
to yours with regard to the context of the problem. so what's going on.
I think (I know) I forgot to mention one tiny little detail.
the whole 'include' code occurs in a script that forks itself ...
the script forks itself a number of times and each child then performs
the include.
so I tested the fork issue with your script ... it still bloody works,
(see the for loop below) so it's something else ... I thought it might
be the difference between using ob_get_clean() and ob_get_contents()+ob_end_clean()
but that doesn't seem to be it either.
the worse thing is my script has just stopped outputting the shebang lines of
the included script(s) ... oh well ... the problem is solved, dunno how, dunno why,
situations like these I'd rather the problem didn't go away .. I prefer to know
wtf happened!
----<test.php>----
#!/usr/bin/php
<?php
echo "arse\n";
for ($i = 0; $i < 3; $i++) {
$pid = pcntl_fork();
if ($pid == 0) {
echo Inc('testinc.php');
exit;
}
}
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php