首页  >  文章  >  后端开发  >  ob_end_clean 出错了,求教!

ob_end_clean 出错了,求教!

WBOY
WBOY原创
2016-06-23 14:05:18902浏览

我想用set_error_handler来统一收集错误,在打印自定义错误提示前,我用了ob_end_clean();但是报错了

PS:我开启了gzip

测试代码:

error_reporting(E_ALL);set_error_handler(array('test', 'handle_error'));if(function_exists('ob_gzhandler')) {    ob_start('ob_gzhandler');} else {    ob_start();}class test {        public static function handle_error($errno, $errstr, $errfile, $errline) {        if($errno) {             debug::system_error($errstr);        }    }}class debug {        public static function system_error($message) {        ob_end_clean();                echo $message;                exit;    }}echo '错误前信息<br/>';trigger_error('错误内容');


上述代码测试,就报错了。。。ob_end_clean()注释掉就没关系。。。

我对ob_start理解不深,求赐教!


回复讨论(解决方案)

顺便贴一下错误:
chrome浏览器下
错误 330 (net::ERR_CONTENT_DECODING_FAILED):未知错误

error_reporting(E_ALL);set_error_handler(array('test', 'handle_error'));if(function_exists('ob_gzhandler')) {    ob_start('my_ob_gzhandler');} else {    ob_start();}class test {    public static function handle_error($errno, $errstr, $errfile, $errline) {        if($errno) {            debug::system_error($errstr);        }    }}class debug {    public static function system_error($message) {        ob_clean();        echo $message;        exit;    }}echo '错误前信息<br/>';trigger_error('ddddddddddddddddddddddddd误内容');function my_ob_gzhandler($buffer,$mod){    header("Content-Encoding: gzip");    return gzencode($buffer, 9, FORCE_GZIP);}

PHP code?1234567891011121314151617181920212223242526272829303132333435363738394041error_reporting(E_ALL); set_error_handler(array('test', 'handle_error'));  if(function_exists('ob_gzhandl……

人才啊,,,感谢

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn