php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46903 ob_start(): Special $chunk_size value of 1 is not honoured in HEAD
Submitted: 2008-12-18 14:40 UTC Modified: 2008-12-28 19:52 UTC
From: robin_fernandes at uk dot ibm dot com Assigned: robinf
Status: Closed Package: Output Control
PHP Version: 6CVS-2008-12-18 (snap) OS:
Private report: No CVE-ID:
 [2008-12-18 14:40 UTC] robin_fernandes at uk dot ibm dot com
Description:
------------
The doc for ob_start() states:
"If the optional parameter chunk_size  is passed, the buffer will be flushed after any output call which causes the buffer's length to equal or exceed chunk_size . Default value 0 means that the function is called only in the end, other special value 1 sets chunk_size  to 4096."

In HEAD, setting $chunk_size=1 actually does set the buffer threshold size to 1 byte, rather than 4096 bytes as on 5_* and as documented.

Here's a simple patch for HEAD to restore the documented behaviour:

Index: output.c
===================================================================
RCS file: /repository/php-src/main/output.c,v
retrieving revision 1.214
diff -u -w -p -r1.214 output.c
--- output.c	18 Aug 2008 07:45:59 -0000	1.214
+++ output.c	18 Dec 2008 14:23:10 -0000
@@ -1342,6 +1342,8 @@ PHP_FUNCTION(ob_start)
 	}
 	if (chunk_size < 0) {
 		chunk_size = 0;
+	} else if (chunk_size == 1) {
+		chunk_size = 4096;
 	}
 	
 	if (SUCCESS != php_output_start_user(output_handler, chunk_size, flags TSRMLS_CC)) {

Reproduce code:
---------------
<?php
function flushCounter($input) {
	static $counter=0;
	return '[' . ++$counter . "] $input \n";
}

// This should set the buffer size to 4096
ob_start('flushCounter', 1);

// Get the buffer size: 
$bufferInfo = ob_get_status(true);
var_dump($bufferInfo[0]['chunk_size']);

// If the buffer size is >1, these two chars should
// come out as part of a single flush:
echo "1";
echo "2";
?>

Expected result:
----------------
[1] int(4096)
12 


Actual result:
--------------
[1] int(1)
 
[2] 1 
[3] 2 
[4]  

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-23 19:10 UTC] felipe@php.net
Commit it :)
 [2008-12-28 19:52 UTC] robinf@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 14:02:33 2014 UTC