php ob_flush,flush在ie中缓冲无效的解决方法_PHP
PHP程序的缓冲,而不论PHP执行在何种情况下(CGI ,web服务器等等)。该函数将当前为止程序的所有输出发送到用户的浏览器。
flush() 函数不会对服务器或客户端浏览器的缓存模式产生影响。因此,必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。
个别web服务器程序,特别是Win32下的web服务器程序,在发送结果到浏览器之前,仍然会缓存脚本的输出,直到程序结束为止
自己写了个小例子,想在页面每隔一秒输出一个数字。
按照网上的代码:
复制代码 代码如下:
ob_end_clean();
for ($i=10; $i>0; $i--)
{
echo $i;
flush();
sleep(1);
}
或者:
复制代码 代码如下:
for ($i=10; $i>0; $i--)
{
echo $i;
ob_flush();
flush();
sleep(1);
}
我发现在火狐里面生效,但在IE里不起作用,每次都是10个数字一起输出,这说明缓冲没有生效。
我又开始调整php.ini里面的output_buffering的设置,重启apache,依旧无效。
然后我看到了一段话:
一些版本的 Microsoft Internet Explorer 只有当接受到的256个字节以后才开始显示该页面,所以必须发送一些额外的空格来让这些浏览器显示页面内容。
罪恶的IE浏览器,问题就是TMD的多!
然后我修改了下程序,便正常了:
复制代码 代码如下:
echo str_pad('',4096);
for ($i = 0; $i echo $i;
ob_flush();
flush();
sleep(1);
}
复制代码 代码如下:
//ob_end_flush();//IE8下没起作用
echo str_pad(" ", 256);//IE需要接受到256个字节之后才开始显示
for($i=0;$iecho $i;
flush();
sleep(1);
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
