Skip to content

Update ob_get_status and ob_start documentation - #5260

Open
lacatoire wants to merge 1 commit into
php:masterfrom
lacatoire:fix/ob-get-status-buffer-size-doc
Open

Update ob_get_status and ob_start documentation#5260
lacatoire wants to merge 1 commit into
php:masterfrom
lacatoire:fix/ob-get-status-buffer-size-doc

Conversation

@lacatoire

@lacatoire lacatoire commented Feb 5, 2026

Copy link
Copy Markdown
Member

ob_get_status() documents buffer_size as "Output buffer size in bytes", which says nothing about what the number means or why it moves. The linked issue also asks why chunk_size of 0 and 1 produce different buffer_size values.

The allocation rule is in main/php_output.h:

#define PHP_OUTPUT_HANDLER_INITBUF_SIZE(s) \
( ((s) > 0) ? ZEND_MM_ALIGNED_SIZE_EX(s, PHP_OUTPUT_HANDLER_ALIGNTO_SIZE) \
            : PHP_OUTPUT_HANDLER_DEFAULT_SIZE )
#define PHP_OUTPUT_HANDLER_ALIGNTO_SIZE   0x1000   //  4096
#define PHP_OUTPUT_HANDLER_DEFAULT_SIZE   0x4000   // 16384

Measured on PHP 8.5.4:

chunk_size=0      -> buffer_size=16384
chunk_size=1      -> buffer_size=4096
chunk_size=100    -> buffer_size=4096
chunk_size=4096   -> buffer_size=4096
chunk_size=10000  -> buffer_size=12288

growth with the default chunk_size:
  16000 bytes written -> 16384       16384 -> 32768
  40000 bytes written -> 40960      100000 -> 102400

So the initial size is 16384 with the default chunk_size, not one memory page, and any explicit chunk_size is rounded up to the next multiple of 4096. Both pages now state that.

The flush behaviour of chunk_size = 1 is documented as well, verified with an output callback: echo "A"; echo "B"; echo "C"; reaches the callback as three separate chunks with chunk_size = 1, as a single "ABC" with 0, and as "AB", "CD" with 2.

Fixes: #3816

@lacatoire lacatoire changed the title Clarify ob_get_status buffer_size and ob_start chunk_size behavior Update ob_get_status and ob_start documentation Mar 2, 2026
@lacatoire lacatoire closed this Mar 2, 2026
@lacatoire lacatoire reopened this Aug 21, 2026
@lacatoire
lacatoire force-pushed the fix/ob-get-status-buffer-size-doc branch 2 times, most recently from 10782f8 to 296fb4b Compare August 21, 2026 10:04
@lacatoire
lacatoire force-pushed the fix/ob-get-status-buffer-size-doc branch from 296fb4b to 14f483c Compare August 21, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ob_get_status buffer_size vs chunk_size

1 participant