Here goes a workaround if you can't use fast cgi.
You'll need to replace echo with puts function everywhere:
<?php
function puts(){
static $init = false;
$numargs = func_num_args();
$arg_list = func_get_args();
$string = '';
if($numargs === 0)
return;
else if($numargs > 1)
$string = implode('', $arg_list);
else
$string = $arg_list[0];
if($init === false)
{
if(ob_start("ob_gzhandler")){
connsettings('compression', true);
echo 'Yes compression';
}else{
ob_start();
echo 'No compression<br>';
}
$init = true;
register_shutdown_function('puts', null, true);
}
echo $string;
}
function connsettings(){
static $settings= array();
$numargs = func_num_args();
$arg_list = func_get_args();
$name = $arg_list[0];
if($numargs === 1)
return $settings[$name] ?? null;
$oldVal = $settings[$name] ?? null;
$settings[$name]= $arg_list[1];
return $oldVal;
};
function connection_close(){
if(!headers_sent()){
set_time_limit(0);
ignore_user_abort(true);
ob_end_flush(); if(connsettings('compression') === false)
header("Content-Encoding: none");
header('Content-Length: ' . ob_get_length());
header('Connection: close');
if(ob_get_level() > 0)
ob_flush();
flush();
}
}
puts('Whatever you want to print...<br>');
puts('Some more<br>');
connection_close();
puts("It's never gonna be seen<br>");
echo 'Neither this';
?>