php ob_flush flush 输出缓存实例与说明_PHP教程

php教程评论781 views阅读模式

使用ob_flush()前,确保前面的内容大小足够4069字符。一些Web服务器的output_buffering默认是4069字符或者更大,即输出内容必须达到4069字符服务器才会flush刷新输出缓冲,为了确保flush有效

php教程 ob_flush flush 输出缓存实例与说明

*/

ob_flush();

//

flush();

//

function flush (){

echo(str_repeat(' ',256));

// check that buffer is actually set before flushing

if (ob_get_length()){

@ob_flush();

@flush();

@ob_end_flush();

}

@ob_start();

}

//str_repeat(string,repeat) 把字符串重复指定的次数。

//实例二

@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
ob_implicit_flush(1);

/*
使用注意事项:
flush和ob_flush的使用上有一些特别容易犯错的地方,造成无法刷新输出缓冲。

一. flush和ob_flush的正确顺序,正确应是,先ob_flush再flush,如下:

以下为引用的内容:

ob_flush();

flush();

如果web服务器的操作系统是windows系统,那顺序颠倒或者不使用ob_flush()也不会出现问题。但是在linux系统上就无法刷新输出缓冲。

二. 使用ob_flush()前,确保前面的内容大小足够4069字符。
一些web服务器的output_buffering默认是4069字符或者更大,即输出内容必须达到4069字符服务器才会flush刷新输出缓冲,为了确保flush有效

企鹅博客
  • 本文由 发表于 2020年9月20日 10:25:28
  • 转载请务必保留本文链接:https://www.qieseo.com/307423.html

发表评论