|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-11-21 16:54 UTC] vrana@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 08:00:01 2025 UTC |
Description: ------------ The manual for ob_start() provides the following description for the chunk_size parameter: "If the optional parameter chunk_size is passed, the callback function is called on every first newline after chunk_size bytes of output. Default value 0 means that the function is called only in the end, other special value 1 sets chunk_size to 4096." I believe There are two problems with that statement. 1. Passing the chunk_size does not just cause the callback function to be called. It causes a flush of the buffer, which will in turn trigger the callback function, if one is available. This is important, since the documentation explains how it is possible to set a chunk_size and erase flag without a callback function by providing null as the first argument. 2. The flush does not occur "on every first newline after chunk_size bytes". It occurs after any append to the buffer which has caused the buffer length to equal or exceed the chunk_size. Newlines are not treated differently from other characters. Evidence for this is in the code in output.c in php_ob_append(): if (OG(active_ob_buffer).chunk_size && OG(active_ob_buffer).text_length >= OG(active_ob_buffer).chunk_size) { php_end_ob_buffer(1, 1 TSRMLS_CC); return; } So, I think the statement should read: 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. There are two special values: 0 (default value): the buffer is flushed only when explicitly called for (for example with ob_flush()) or at the end of the request. 1: equivalent to setting chunk_size to 4096. Note that flushing the buffer will trigger the callback function, if it is available. Reproduce code: --------------- Here is a test demonstrating that a buffer is flushed after an output call causes its length to equal or exceed chunk_size, and that this is not dependent on the occurrence of new lines: http://pastebin.com/f46cbdf76 Expected result: ---------------- N/A Actual result: -------------- N/A