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

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

WBOY
WBOYOriginal
2016-06-13 11:18:241064browse

使用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_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有效


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn