1--TEST--
2ob_start() chunk_size: confirm buffer is flushed after any output call that causes its length to equal or exceed chunk_size.
3--FILE--
4<?php
5/*
6 * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]])
7 * Function is implemented in main/output.c
8*/
9// In HEAD, $chunk_size value of 1 should not have any special behaviour (http://marc.info/?l=php-internals&m=123476465621346&w=2).
10function callback($string) {
11	global $callback_invocations;
12	$callback_invocations++;
13	$len = strlen($string);
14	return "f[call:$callback_invocations; len:$len]$string\n";
15}
16
17for ($cs=-1; $cs<10; $cs++) {
18  echo "\n----( chunk_size: $cs, output append size: 1 )----\n";
19  $callback_invocations=0;
20  ob_start('callback', $cs);
21  echo '1'; echo '2'; echo '3'; echo '4'; echo '5'; echo '6'; echo '7'; echo '8';
22  ob_end_flush();
23}
24
25for ($cs=-1; $cs<10; $cs++) {
26  echo "\n----( chunk_size: $cs, output append size: 4 )----\n";
27  $callback_invocations=0;
28  ob_start('callback', $cs);
29  echo '1234'; echo '5678';
30  ob_end_flush();
31}
32
33?>
34--EXPECTF--
35
36----( chunk_size: -1, output append size: 1 )----
37f[call:1; len:8]12345678
38
39----( chunk_size: 0, output append size: 1 )----
40f[call:1; len:8]12345678
41
42----( chunk_size: 1, output append size: 1 )----
43f[call:1; len:1]1
44f[call:2; len:1]2
45f[call:3; len:1]3
46f[call:4; len:1]4
47f[call:5; len:1]5
48f[call:6; len:1]6
49f[call:7; len:1]7
50f[call:8; len:1]8
51f[call:9; len:0]
52
53----( chunk_size: 2, output append size: 1 )----
54f[call:1; len:2]12
55f[call:2; len:2]34
56f[call:3; len:2]56
57f[call:4; len:2]78
58f[call:5; len:0]
59
60----( chunk_size: 3, output append size: 1 )----
61f[call:1; len:3]123
62f[call:2; len:3]456
63f[call:3; len:2]78
64
65----( chunk_size: 4, output append size: 1 )----
66f[call:1; len:4]1234
67f[call:2; len:4]5678
68f[call:3; len:0]
69
70----( chunk_size: 5, output append size: 1 )----
71f[call:1; len:5]12345
72f[call:2; len:3]678
73
74----( chunk_size: 6, output append size: 1 )----
75f[call:1; len:6]123456
76f[call:2; len:2]78
77
78----( chunk_size: 7, output append size: 1 )----
79f[call:1; len:7]1234567
80f[call:2; len:1]8
81
82----( chunk_size: 8, output append size: 1 )----
83f[call:1; len:8]12345678
84f[call:2; len:0]
85
86----( chunk_size: 9, output append size: 1 )----
87f[call:1; len:8]12345678
88
89----( chunk_size: -1, output append size: 4 )----
90f[call:1; len:8]12345678
91
92----( chunk_size: 0, output append size: 4 )----
93f[call:1; len:8]12345678
94
95----( chunk_size: 1, output append size: 4 )----
96f[call:1; len:4]1234
97f[call:2; len:4]5678
98f[call:3; len:0]
99
100----( chunk_size: 2, output append size: 4 )----
101f[call:1; len:4]1234
102f[call:2; len:4]5678
103f[call:3; len:0]
104
105----( chunk_size: 3, output append size: 4 )----
106f[call:1; len:4]1234
107f[call:2; len:4]5678
108f[call:3; len:0]
109
110----( chunk_size: 4, output append size: 4 )----
111f[call:1; len:4]1234
112f[call:2; len:4]5678
113f[call:3; len:0]
114
115----( chunk_size: 5, output append size: 4 )----
116f[call:1; len:8]12345678
117f[call:2; len:0]
118
119----( chunk_size: 6, output append size: 4 )----
120f[call:1; len:8]12345678
121f[call:2; len:0]
122
123----( chunk_size: 7, output append size: 4 )----
124f[call:1; len:8]12345678
125f[call:2; len:0]
126
127----( chunk_size: 8, output append size: 4 )----
128f[call:1; len:8]12345678
129f[call:2; len:0]
130
131----( chunk_size: 9, output append size: 4 )----
132f[call:1; len:8]12345678