Bug #17825: problem using chunk_size argument to ob_start()

From: Date: Wed, 19 Jun 2002 01:35:41 +0000
Subject: Bug #17825: problem using chunk_size argument to ob_start()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-11325@lists.php.net to get a copy of this message
From: hhr02368@haris.org Operating system: linux redhat 6.2 PHP version: 4.2.1 PHP Bug Type: Output Control Bug description: problem using chunk_size argument to ob_start() 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 -- Edit bug report at http://bugs.php.net/?id=17825&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=17825&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=17825&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=17825&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=17825&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=17825&r=support Expected behavior: http://bugs.php.net/fix.php?id=17825&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=17825&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=17825&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=17825&r=globals

« previous php.bugs (#11325) next »