PHP 刷新和 WAMP 服务器
我无法使用 WAMP 使 PHP 刷新功能正常工作。这是一些示例代码,注释掉了我尝试过的所有不同的事情:
//apache_setenv('no-gzip', 1); // returns error that apache_setenv does not exist
//ini_set('zlib.output_compression',0);
//ini_set('implicit_flush',1);
//ob_end_clean();
//for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
//ob_implicit_flush(1);
set_time_limit(0);
echo "<pre>";
for ($i = 0; $i < 100; ++$i) {
echo $i.' '.time().str_repeat(' ',256)."\n";
//ob_flush(); // returns error without output buffering enabled
flush();
usleep(100000);
}
似乎无论我做什么,我总是将结果集中在一个巨大的块中。
编辑: 我已将完全相同的代码上传到在 cPanel/linux 上运行的服务器,并且它在所有浏览器中都能完美运行。为什么我不能让它在本地 WAMP 服务器上正常工作?
I can't for the life of me get the PHP flush function to work properly, using WAMP. Here is some sample code, commented out are all of the different things I've tried:
//apache_setenv('no-gzip', 1); // returns error that apache_setenv does not exist
//ini_set('zlib.output_compression',0);
//ini_set('implicit_flush',1);
//ob_end_clean();
//for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
//ob_implicit_flush(1);
set_time_limit(0);
echo "<pre>";
for ($i = 0; $i < 100; ++$i) {
echo $i.' '.time().str_repeat(' ',256)."\n";
//ob_flush(); // returns error without output buffering enabled
flush();
usleep(100000);
}
It seems no matter what I do, I always get the results all together in one giant chunk.
Edit:
I've uploaded the same exact code to a server running on cPanel/linux, and it works perfect in all browsers. Why can't I get it to work properly on a localhost WAMP server??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
lush() 可能无法覆盖 Web 服务器的缓冲方案,并且它对浏览器中的任何客户端缓冲没有影响。它也不会影响 PHP 的用户空间输出缓冲机制。这意味着如果您正在使用 ob_flush() 和 flash() ,则必须调用它们来刷新 ob 输出缓冲区。
一些服务器,尤其是 Win32 上的服务器,仍然会缓冲脚本的输出,直到脚本终止,然后再将结果传输到浏览器。
Apache 的服务器模块(例如 mod_gzip)可能会进行自己的缓冲,这将导致 flash() 不会导致数据立即发送到客户端。
甚至浏览器也可能在显示输入之前缓冲其输入。例如,Netscape 会缓冲文本,直到收到行尾或标记的开头,并且在看到最外层表格的标记之前不会呈现表格。
某些版本的 Microsoft Internet Explorer 仅在收到 256 字节的输出后才开始显示页面,因此您可能需要在刷新之前发送额外的空格以使这些浏览器显示页面。
flush() may not be able to override the buffering scheme of your web server and it has no effect on any client-side buffering in the browser. It also doesn't affect PHP's userspace output buffering mechanism. This means you will have to call both ob_flush() and flush() to flush the ob output buffers if you are using those.
Several servers, especially on Win32, will still buffer the output from your script until it terminates before transmitting the results to the browser.
Server modules for Apache like mod_gzip may do buffering of their own that will cause flush() to not result in data being sent immediately to the client.
Even the browser may buffer its input before displaying it. Netscape, for example, buffers text until it receives an end-of-line or the beginning of a tag, and it won't render tables until the tag of the outermost table is seen.
Some versions of Microsoft Internet Explorer will only start to display the page after they have received 256 bytes of output, so you may need to send extra whitespace before flushing to get those browsers to display the page.
尝试在flush()之前使用ob_flush();
Try using ob_flush() before flush();