php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17825 problem using chunk_size argument to ob_start()
Submitted: 2002-06-18 21:35 UTC Modified: 2002-10-01 05:09 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: hhr02368 at haris dot org Assigned: yohgaki (profile)
Status: Closed Package: Output Control
PHP Version: 4.3.0-dev OS: linux redhat 6.2
Private report: No CVE-ID: None
 [2002-06-18 21:35 UTC] hhr02368 at haris dot org
Test environment:
A) apache 1.3.24, PHP 4.2.1 built as apache module
B) apache 1.3.23, PHP 4.1.2 built as apache module

The following program demonstrates the change in behavior between 
versions 4.1.2 and 4.2.1:

<?
function output_handler($buffer, $mode) {
    static $s_count;
    $s_count++;
    error_log("output_handler: s_count=$s_count  " . 
    	"strlen(buffer)=" . strlen($buffer) . "\n", 
    	3, '/tmp/logfile');
    return strtoupper($buffer);
}

header("Content-Type: text/plain");
ob_start('output_handler', 400);

for ($i=0; $i<20; $i++) {
    echo sprintf("%5d the quick brown fox jumped over the lazy dog\n", $i);
}
?>

Our expectation is that output_handler() will get called 
multiple times, every time there are more than 100 bytes 
of output to process or when explicit ob_flush is called. 

Running with php 4.2.1 (test environment A) output_handler() 
is called only once:
> cat /tmp/logfile 
>   output_handler: s_count=1  strlen(buffer)=102

The browser displays:
>    0 THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG
>    1 THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG
>    2 the quick brown fox jumped over the lazy dog
>    3 the quick brown fox jumped over the lazy dog
>    4 the quick brown fox jumped over the lazy dog

It appears that after the 1st time, our output is sent to the
browser unprocessed. If using ob_gzhandler() the results are
more unpleasant as the first buffer is compressed but the
rest are sent uncompressed, confusing the browser.

If ob_start() is called without the 2nd argument then 
output_handler() is called once to process the complete 
output. This results in correct output but is undesirable
because for some scripts this buffer can be very large.

Running the same program with php 4.1.2 (test environment B) 
output_handler() is called 3 times:
> cat /tmp/logfile 
>   output_handler: s_count=1  strlen(buffer)=102
>   output_handler: s_count=2  strlen(buffer)=102
>   output_handler: s_count=3  strlen(buffer)=51

The browser displays:
>    0 THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG
>    1 THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG
>    2 THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG
>    3 THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG
>    4 THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG
>    5 THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-29 22:40 UTC] iliaa@php.net
verified & bumped version #.
 [2002-09-30 17:39 UTC] sniper@php.net
be specific about the version..

 [2002-10-01 04:59 UTC] yohgaki@php.net
Found what's wrong.

OG(active_ob_buffer).output_handler is destoryed after 1st call for some reason.

Fix will be committed in a few days.
 [2002-10-01 05:09 UTC] yohgaki@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

It was rather obvious :)

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 03:01:28 2024 UTC