Home > Article > Backend Development > ob_end_clean 出错了,求教!
我想用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('错误内容');
顺便贴一下错误:
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……
人才啊,,,感谢