note 124191 deleted from function.fastcgi-finish-request by salathe
| From: | salathe@php.net | Date: | Thu, 27 Aug 2020 07:58:42 +0000 |
| Subject: | note 124191 deleted from function.fastcgi-finish-request by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215031@lists.php.net to get a copy of this message | ||
Note Submitter: marcelotpcruz at gmail dot com
----
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)
{
// buffer all upcoming output - make sure we care about compression:
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(/*$name, (optional)$val=$arg_list[1]*/){
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())//it may work without this verification when no compression but may lead to
uncomplete data
{
set_time_limit(0);
ignore_user_abort(true);
// send headers to tell the browser to close the connection
ob_end_flush(); // Order here matter, it won't work if it goes after Content-Length
if(connsettings('compression') === false)
header("Content-Encoding: none");
header('Content-Length: ' . ob_get_length());
header('Connection: close');
// flush all output
if(ob_get_level() > 0)
ob_flush();
flush();
}
}
//Usage
puts('Whatever you want to print...<br>');
puts('Some more<br>');
connection_close();
puts("It's never gonna be seen<br>");
echo 'Neither this';
?>