【发布时间】:2013-06-14 18:08:11
【问题描述】:
我正在尝试实现此页面上列出的技巧http://developer.yahoo.com/performance/rules.html#flush“尽早刷新缓冲区”。
每次我尝试运行这个东西时,我都没有得到想要的输出。
我已经编写了以下代码。
<html>
<head>
<title>This is title</title>
<script type="text/javascript" src="/1.js"></script>
<link rel="stylesheet" type="text/css" href="/1.css">
</head>
<body>
ABC
<?php
flush();
sleep(3);
?>
</body>
</html>
结果
我在 Firefox 和 Chrome 上都得到了相同的结果。
我希望 CSS 和 JS 文件的下载应该立即开始,而不是等待 3 秒。
根据互联网上提供的信息,我尝试了以下方法,但没有任何帮助。
1. ob_start(); and then ob_flush();
2. Using both ob_flush(); and flush(); ( in both the orders )
3. Adding the thing like this
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
4. Putting more content in body 4~5 KB of content before flush.
5. And many other things.
我怀疑是否真的可以实现这种事情。
【问题讨论】:
-
你的意思是说我不应该这样做?按照帖子的最高答案。我想告诉你,我不会做 G-Zip,我只会合并和缩小 CSS 和 JS 文件。此外,在我的情况下,完成整个 PHP 脚本通常需要 2-2.5 秒 + 还会出现大量图像。这样做意味着少了 2 个 HTTP 请求。另外,我不会经常冲洗,我打算在
</head>之后冲洗一次,在</html>之后冲洗一次 -
你在另一个像 nginx 这样的 http 服务器后面吗?这个问题可能是相关的:PHP Flush that works… even in Nginx
-
@Lepidosteus.. 不,我只是在使用 Apache。
-
我现在遇到了同样的问题,@Manu,你找到解决方案了吗?这与我面临的问题非常相似!
标签: php performance flush buffering output-buffering