<?php

if (function_exists('apache_setenv')) {
  apache_setenv('no-gzip', 1);
}
@ini_set('zlib.output_compression', 0);
while(ob_get_level()){ob_end_flush();}

header("Transfer-Encoding: chunked");
header("Content-Type: text/plain");
flush();


function getThingsToSay() {
  $results = [];
  for ($i = 0; $i < 40; $i++) {
    $output = [];
    exec('/usr/games/fortune', $output);
    $results[] = implode("\n", $output);
  }
  return $results;
}

function send_chunk($chunk) {
  printf("%x\r\n", strlen($chunk));
  print $chunk;
  print "\r\n";
  flush();
}

$things = getThingsToSay();
send_chunk("Done loading fortunes.\n");
sleep(2);

foreach ($things as $fortune) {
 send_chunk($fortune . "\n\n");
 usleep(3e5);
}

send_chunk('');
print "\r\n";

<?php

if (function_exists('apache_setenv')) {
  apache_setenv('no-gzip', 1);
}
@ini_set('zlib.output_compression', 0);
while(ob_get_level()){ob_end_flush();}

header("Transfer-Encoding: chunked");
header("Content-Type: text/plain");
flush();


function getThingsToSay() {
  $results = [];
  for ($i = 0; $i < 80; $i++) {
    $output = [];
    exec('/usr/games/fortune', $output);
    $results[] = implode("\n", $output);
  }
  return $results;
}

function send_chunk($chunk) {
  printf("%x\r\n", strlen($chunk));
  print $chunk;
  print "\r\n";
  flush();
}

$things = getThingsToSay();
send_chunk("Done loading fortunes.\n");
sleep(2);

foreach ($things as $fortune) {
 send_chunk($fortune . "\n\n");
 usleep(3e5);
}



--- 
+++ 
@@ -13,7 +13,7 @@
 
 function getThingsToSay() {
   $results = [];
-  for ($i = 0; $i < 80; $i++) {
+  for ($i = 0; $i < 40; $i++) {
     $output = [];
     exec('/usr/games/fortune', $output);
     $results[] = implode("\n", $output);
@@ -37,4 +37,5 @@
  usleep(3e5);
 }
 
-
+send_chunk('');
+print "\r\n";
Add chunked transfer encoding terminator
