dongpao1926 2014-12-01 22:05
浏览 55
已采纳

PHP ob_gzhandler额外的字符

I have a blended website where we have an ExpressionEngine CMS with a Magento store. In our EE site, I have a template where I call a plugin to retrieve the store cart info. We use Magento's authentication so the logged in user is the Magento user.

We want to show something like this:

first

The code in the plugin connects to Magento, gets the loggedin user, if they are logged in and sets the number of cart items.

This is the HTML that the plugin is supposed to return to the template:

<span class="carticon">(0)</span><a href="http://www.example.com/store/checkout/cart/">My Cart</a><span>Welcome, MB34!</span><a href="http://www.example.com/store/customer/account/logout/">Logout</a>

But, if I enable gZip on ExpressionEngine, I get the ERR_CONTENT_DECODING_FAILED exception because Magento doesn't have built-in gZip. Currently we do not have mod_deflate enabled so how would EE be able to gZip? It has to be through the ob_gzhandler.

Now, if I modify my plugin to use ob_gzhandler like this:

ob_start("ob_gzhandler");
echo trim($result);
ob_end_flush();

I get extra characters at the end of the output:

second

Any ideas what is causing this and how to fix it?

We will be enabling mod_deflate soon; will that fix it? I mean I won't have to use the ob_gzhandler then, right?

  • 写回答

2条回答 默认 最新

  • dongqun1656 2014-12-01 22:09
    关注

    When using ob_gzhandler its important that you don't mix content with other encodings. By forcing ob_end_flush() you may be causing this buffer to terminate before you are actually done sending content. A simple empty line by the end of the file may be causing this. I suggest you skip ob_end_flush() and let the buffer end naturally when your PHP script terminates.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度