Why does ob_start('ob_gzhandler') break this website?

自作多情 提交于 2019-12-10 16:44:50

问题


I've got a site that throws a Content Encoding Error in the browser if a ob_start('ob_gzhandler') is present. If I remove the statement, it runs fine.

  • The site runs off the same framework, server and hosting package as a number of other sites. They all work, regardless of if the statement is in there.
  • The statement is in the framework, not the application code, so it is shared by all of the sites.
  • There's no difference in the configuration between the working sites and non working site.
  • The site runs fine locally, using the exact same code and data.
  • You can fetch the site with curl / wget, and the HTML returned renders fine in a browser.
  • The response headers are exactly the same, with out without the statement.

I've now removed all of the code on the remote server, and re-uploaded everything. Still no change. The next step would be to re-install the site, and start from scratch, but I don't want to loose all of the data.

Any pointers, suggestions or solutions?


回答1:


usually I do below and it works for me, give it a try

Write ob_end_clean(); or ob_flush(); at the bottom of the page where you start ob_start();

References:

ob_end_clean();

ob_flush();




回答2:


Just Put this line of code in starting and everything will be fine..

while (ob_get_level() > 0) { ob_end_clean() ; } 



回答3:


If you're using Apache's gzip compression already (which by the looks of it you do, since CSS/JS are compressed as far as I can see), then using ob_start('ob_gzhandler') will compress that compression... and the browser won't be able to handle it.

I'm speaking under correction of course as I've always used Apache to do it for me, but it looks like you're double gzipping things, that's why it works without the "ob_gzhandler" statement.

Check your .htaccess files on the other sites and compare it with the site you're running that has the same problem as I can't see that you're running Drupal on zacoders.net and jadeit.co.za, just on jadeit.co.za which makes me think they're not the same framework as you said they are? shrug



来源:https://stackoverflow.com/questions/5441784/why-does-ob-startob-gzhandler-break-this-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!