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条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line