使用ob_flush();停止脚本执行

时间:2011-09-04 23:44:39

标签: php output-buffering

我正在使用php 5.3

我想要的是逐页刷新网页。

Yahoo best practices.

上所说的那样

所以我在head标签之后使用ob_flush();并且脚本停止执行

我也试过flush();也没用。我在网上乱逛,没有找到答案。

这是代码..

function ob_crush($buffer) {
  if(strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) {
    $buffer = gzencode(trim(preg_replace('/\s+/', ' ', $buffer)), 9);
    header('Content-Encoding: gzip');
    return $buffer;
  } else {
    return false;
  }
}

ob_start('ob_crush');

include_once('header.tpl'); // i can see this template.

ob_flush();

include_once('body.tpl'); // i cant see this one.

提前感谢。

修改

根据您的意见(谢谢)

我开始了一个空白的php页面,并将其添加到它。

ob_start('ob_gzhandler');
echo 'hello';
flush();
ob_flush();
sleep(10);
echo '<br />world';
ob_end_flush();

工作正常

然后我做了这个测试。

ob_start('ob_crush');
echo 'hello';
flush();
ob_flush();
sleep(10);
echo '<br />yes';
ob_end_flush();

它只显示'hello'并停止了剧本。

我认为问题出在这个功能上。

    function ob_crush($buffer) {
     if(strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) {
        $buffer = gzencode(trim(preg_replace('/\s+/', ' ', $buffer)), 9);
        header('Content-Encoding: gzip');
        return $buffer;
     } else {
        return false;
     }
   }

0 个答案:

没有答案
相关问题