Bug #80026 [Opn->Nab]: custom ob_start with ob_gzhandler resending headers and generating corrupted ou
Edit report at https://bugs.php.net/bug.php?id=80026&edit=1
ID: 80026
Updated by: cmb@php.net
Reported by: marcelotpcruz at gmail dot com
Summary: custom ob_start with ob_gzhandler resending headers
and generating corrupted ou
-Status: Open
+Status: Not a bug
Type: Bug
Package: HTTP related
Operating System: Windows 10
PHP Version: 7.4.9
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
Both scripts are erroneous; see
<https://www.php.net/ob_gzhandler>.
Previous Comments:
------------------------------------------------------------------------
[2020-08-27 15:08:35] marcelotpcruz at gmail dot com
Description:
------------
When using ob_start with a custom calback ob_gzhandler tries resending headers and also generate a
corrupted output.
Both generates same headers with exception of:
//Response Headers
Keep-Alive: timeout=5, max=100 // Script with fine Output
Keep-Alive: timeout=5, max=99 // Script with bad output
//Request Headers
Sec-Fetch-Site: none // Script with fine Output
Sec-Fetch-Site: same-origin // Script with bad Output
Test script:
---------------
// Script with fine Output
<?php
header( 'Content-type: text/html; charset=utf-8' );
ob_start("ob_gzhandler");
echo 'Begin ...<br />';
for( $i = 0 ; $i < 5 ; $i++ )
{
echo $i . '<br />';
ob_end_flush();
flush();
ob_flush();
ob_start("ob_gzhandler");
sleep(1);
}
echo 'End ...<br />';
// Script with bad Output
<?php
function ob_chunked_gzhandler($buffer, $phase)
{ //compression on
$buffer = ob_gzhandler($buffer, $phase);//<--fourth line
$length = strlen($buffer);
return dechex($length) . "\r\n$buffer\r\n";
}
header('Content-type: text/html; charset=utf-8');
ob_start("ob_chunked_gzhandler");
echo 'Begin ...<br />';
for ($i = 0; $i < 10; $i++) {
echo $i . '<br />';
ob_end_flush();
flush();
ob_flush();
ob_start("ob_chunked_gzhandler");
sleep(1);
}
echo 'End ...<br />';
Expected result:
----------------
//Outputs fine:
Begin ...
0
1
2
3
4
End ...
Actual result:
--------------
55RW sJM��S��ӳI*Rз3�P���2 1b �
3�I*RзR�4) 1b � 3�I*RзÏ� 1b �
3�I*Rз{��� 1b � 3�I*Rз��{ 1b �
3�I*RзA�{� 1b � 3�I*Rзܧ�� 1b �
3�I*Rзh��J 1b � ��I*Rз�ܬ� 1b �
��I*Rз5�� 21 � s�KQ��ӳI*Rз��B
//Error.log file
[Thu Aug 27 11:53:48.261150 2020] [fcgid:warn] [pid 17632:tid 1148] [client ::1:6687] mod_fcgid:
stderr: PHP Warning: Cannot modify header information - headers already sent by (output started at
C:\\server\\lec\\var\\www\\output_custom.php:16) in C:\\server\\lec\\var\\www\\output_custom.php on
line 4, referer: http://localhost/
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80026&edit=1
Thread (2 messages)