不能得到的flush()在Windows工作 [英] Can't get flush() working in Windows

查看:134
本文介绍了不能得到的flush()在Windows工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有这个简单的脚本工作正常在哪里它输出数字的Ubuntu的测试服务器每秒到浏览器

We have a ubuntu test server that this simple script works fine on where it outputs a number each second to the browser

<?
    for ($i=0; $i<3; $i++) 
    {
        echo $i.'<br>';
        flush();
        sleep(1);
    }

不过在我的地方发展对话框(Windows环境)我无法得到它的工作,它输出这一切后3秒。

However on my local development box (windows environment) I cannot get it to work, it outputs it all after 3 seconds.

我使用的是相同的PHP版本(5.3.13)以及阿帕奇(2.2.22)的版本,我的本地盒作为测试服务器。
我已经反映大部分设置在两个php.ini中以及在httpd.conf
这里是我的设置已设置(这是相同的测试服务器)

I am using the same php version (5.3.13) as well as apache (2.2.22) version on my local box as the test server. I have mirrored most of the settings in both php.ini as well as the httpd.conf Here are settings I have set (which are identical to the test server)

output_buffering 0
zlib.output_compression = Off
zlib.output_compression_level = -1

我没有安装mod_gzip的。

I don't have mod_gzip installed.

我甚至尝试过做一个WAMP安装在我的箱子,并没有与工作,要么。

I have even tried doing a wamp install on my box, and it didn't work with that either.

我无法想象它是一个客户端(浏览器 - 火狐13),因为我使用完全相同的浏览器来查看测试服务器上的脚本问题,并能正常工作

I can't imagine it being a client (browser -- firefox 13) issue as I use the exact same browser to view the script on the test server and it works fine

我试图使隐含的冲洗,做使用ob_flush等没有运气。

I have tried enabling implicit flush, doing ob_flush, etc. No luck.

任何人有关于如何得到这个工作什么想法?

Anyone have any ideas on how to get this working?

推荐答案

只要记住什么@Wrikken说,这是不推荐的。

Just keep in mind what @Wrikken said, this is not recommended.

所以我在想,你做的一切似乎是正确的。我复制你的设置和尝试。我面临同样的问题。我从命令行执行的脚本,它的工作。

So I was thinking, everything you're doing seems to be right. I copied your setup and tried. I faced same problem. I executed the script from command line, it worked.

然后我不得不做最后的测试,Wireshark的。继前几包,很明显,服务器正确发送一切,所以它必须是浏览器的缓存。

Then I had to do the last test, Wireshark. Following the first couple of packets it was clear that the server is sending everything correctly, so it had to be the browser’s buffer.

所以,我想在循环之前发送一些数据,以及你猜怎么着?它的工作!

So I tried send some data before the loop, well guess what? It worked!

在这里你去:

<?php
ini_set('output_buffering','off');
ini_set('zlib.output_compression', 0);
echo str_repeat(" ", 1024), "\n";
for($i=0;$i<6;$i++) {
      echo $i."<br />\n";
      ob_flush();
      flush();
      sleep(1);
}
?>

我不知道你心目中的应用程序,但是这显然不是一个好主意,我强烈建议你看看其他的选择。

I'm not sure about the application you have in mind, but this is clearly not a good idea, I highly recommend that you look into other options.

更新:
悠悠谷歌搜索后,我发现并的这个

由于浏览器无法正确渲染页面,不知道如何
  构建页面的人物,大多数浏览器缓冲一定
  在执行任何JavaScript或绘图页之前的字节数

Because a browser cannot correctly render a page without knowing how to construct the page's characters, most browsers buffer a certain number of bytes before executing any JavaScript or drawing the page

要避免这些延误,你应该总是指定字符
  尽早,为任何HTML文档大于1 KB的编码
  ( 1024个字节,以precise,这是由使用的最大缓冲区限制
  任何我们所测试的浏览器)的。

To avoid these delays, you should always specify the character encoding as early as possible, for any HTML document larger than 1 KB (1024 bytes, to be precise, which is the maximum buffer limit used by any of the browsers we have tested).

于是,我就发送的字符集,而不是先填充缓冲区(和它的工作)

So I tried to send the charset first instead of filling the buffer: (and it worked)

<?php
ini_set('output_buffering','off');
ini_set('zlib.output_compression', 0);
//echo str_repeat(" ", 1024), "\n";
header('Content-Type: text/html; charset=iso-8859-1');
//Note that it shoudn't matter which charset you send
for($i=0;$i<6;$i++) {
      echo $i."<br />\n";
      ob_flush();
      flush();
      sleep(1);
}
?>

那么,为什么它的第一台服务器,但不工作的第二个?

最有可能是因为你的第一个服务器发送的报头中的字符集,而第二个是没有的。

Most likely it's because your first server is sending the charset with the header while the second one isn't.

在您的情况,但是,我会做以下修改

In your case, however, I'd make the following changes

<?php
ini_set('output_buffering','off');
ini_set('zlib.output_compression', 0);
//Plain text MIME type since you'll use for logging purposes
//and if you run it from CLI, you can ignore the whole header line
header('Content-Type: text/plain; charset=iso-8859-1');
for($i=0;$i<6;$i++) {
      //No need to echo <br /> once you'll run it from CLI
      echo $i."\n";
      ob_flush();
      flush();
      sleep(1);
}
?>

这篇关于不能得到的flush()在Windows工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆