Good day,
I am getting the following error in PHP :
ob_get_clean(): Failed to discard buffer of ob_gzhandler
I am developing an application under Windows WAMPServer. And I have tried to launch my application today. Unfortunately the first thing I got was content encoding error. Whilst it worked perfectly under WAMP with the following code :
///########-------------------------------------------------------------
///########-------------------------------------------------------------
///######## METHOD : PARSE TEMPLATE
///########-------------------------------------------------------------
///########-------------------------------------------------------------
private static function parse($tpl){
///######## TURN ON OUTPUT BUFFER
ob_start(null, 32768);
///######## ENABLE GZIP ENCODING
ob_start("ob_gzhandler");
///######## ENABLE CACHING
header('Cache-Control: public');
///######## EXPIRES IN ONE {x} SECONDS, {default 86400 seconds (seven days)}
if(self::$cache_expire) header('Expires: '.gmdate('D, d M Y H:i:s', time() + self::$cache_expire).' GMT');
///######## ECHO CODE
echo $tpl;
///######## GET THE OUTBUT BUFFER
$tpl = ob_get_clean();
///######## FLUSH BUFFER
ob_end_flush();
///########==================================================
///######## PARSED CODE
///########==================================================
return $tpl;
///########==================================================
}
This gave under Linux Centos and PHP 8.1 a content encoding error. A little digging on this forum gave me the following :
PHP Output buffering, Content Encoding Error caused by ob_gzhandler?
So I changed my code to :
///########-------------------------------------------------------------
///########-------------------------------------------------------------
///######## METHOD : PARSE TEMPLATE
///########-------------------------------------------------------------
///########-------------------------------------------------------------
private static function parse($tpl){
///######## TURN ON OUTPUT BUFFER
ob_start(null, 32768);
///######## ENABLE GZIP ENCODING
ob_start("ob_gzhandler");
///######## ENABLE CACHING
header('Cache-Control: public');
///######## EXPIRES IN ONE {x} SECONDS, {default 86400 seconds (seven days)}
if(self::$cache_expire) header('Expires: '.gmdate('D, d M Y H:i:s', time() + self::$cache_expire).' GMT');
///######## ECHO CODE
echo $tpl;
///######## FLUSH
ob_flush();
///######## GET THE OUTBUT BUFFER
$tpl = ob_get_clean();
///########==================================================
///######## PARSED CODE
///########==================================================
return $tpl;
///########==================================================
}
That gives me a little more. But unfortunately still an error :
Notice: ob_get_clean(): Failed to discard buffer of ob_gzhandler
Now I have been looking at the examples over and over again.
I found the following thread : failed to delete buffer. No buffer to delete
But the point is. There actually is buffer to clean. So that couldn't be the issue.
Where could my error be?
SOLUTION
I had :
///######## TURN ON OUTPUT BUFFER ob_start(null, 32768); ///######## ENABLE GZIP ENCODING ob_start("ob_gzhandler");
But I should switch these two. Why exactly this is. I don't know. But maybe if someone wants. Add the explanation. But for reference. I still add this "question" so that someone doesn't have to spend a frustrating evening.
///######## ENABLE GZIP ENCODING ob_start("ob_gzhandler"); ///######## TURN ON OUTPUT BUFFER ob_start(null, 32768);
*please close this question