Re: [NOT SOLVEDish] Re: [PHP] output buffering in CLI script.

From: Date: Thu, 28 Feb 2008 14:07:39 +0000
Subject: Re: [NOT SOLVEDish] Re: [PHP] output buffering in CLI script.
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-270557@lists.php.net to get a copy of this message
Jochem Maas schreef: ...
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!
wtf happened was I was looking at the wrong output. I changed my code to be as much like your test code as possible (to the point that I now use a function to perform the buffering and 'include' and returning output) ... the output buffering is not working at all. I've had enough - /dev/null meet script output, output meet /dev/null
----<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


« previous php.general (#270557) next »