ob_start_basic_004.phpt 3.2 KB

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