note 124191 added to function.fastcgi-finish-request
| From: | marcelotpcruz at gmail dot com | Date: | Thu, 12 Sep 2019 08:13:35 +0000 |
| Subject: | note 124191 added to function.fastcgi-finish-request | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-212173@lists.php.net to get a copy of this message | ||
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';
?>
----
Server IP: 208.43.231.9
Probable Submitter: 82.199.157.54 (proxied: 179.178.65.52)
----
Manual Page -- http://php.net/manual/en/function.fastcgi-finish-request.php
Edit -- https://master.php.net/note/edit/124191
Del: integrated -- https://master.php.net/note/delete/124191/integrated
Del: useless -- https://master.php.net/note/delete/124191/useless
Del: bad code -- https://master.php.net/note/delete/124191/bad+code
Del: spam -- https://master.php.net/note/delete/124191/spam
Del: non-english -- https://master.php.net/note/delete/124191/non-english
Del: in docs -- https://master.php.net/note/delete/124191/in+docs
Del: other reasons-- https://master.php.net/note/delete/124191
Reject -- https://master.php.net/note/reject/124191
Search -- https://master.php.net/manage/user-notes.php