ob_flush() - php 输出缓冲函数
ob_flush()
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
冲刷出(送出)输出缓冲区中的内容
说明
ob_flush(void): void这个函数将送出缓冲区的内容(如果里边有内容的话)。如果想进一步处理缓冲区中的内容,必须在ob_flush()之前调用ob_get_contents(),因为在调用ob_flush()之后缓冲区内容将被丢弃。
此函数不会销毁输出缓冲区,而像ob_end_flush()函数会销毁缓冲区。
返回值
没有返回值。
参见
ob_get_contents()
返回输出缓冲区的内容ob_clean()
清空(擦掉)输出缓冲区ob_end_flush()
冲刷出(送出)输出缓冲区内容并关闭缓冲ob_end_clean()
清空(擦除)缓冲区并关闭输出缓冲
some problems with ob_flush() and flush() could be resolved by defining content type header : header( 'Content-type: text/html; charset=utf-8' ); so working code looks like this:
As of August 2012, all browsers seem to show an all-or-nothing approach to buffering. In other words, while php is operating, no content can be shown. In particular this means that the following workarounds listed further down here are ineffective: 1) ob_flush (), flush () in any combination with other output buffering functions; 2) changes to php.ini involving setting output_buffer and/or zlib.output_compression to 0 or Off; 3) setting Apache variables such as "no-gzip" either through apache_setenv () or through entries in .htaccess. So, until browsers begin to show buffered content again, the tips listed here are moot.
Although browsers now have an all or none buffering strategy, the arguments are not moot. If you are not using ob_flush, you run this risk of exceeding socket timeouts (commonly seen in php-fpm/nginx combos). Basically, flushing solves the infamous 504 Gateway Time-out error.
If there is no active output buffer, an error of level E_NOTICE is generated (at least in PHP 7.1). To avoid this, test first with `ob_get_level()`.
If you call ob_flush() and flush() and still dont get the buffer flushed it might be because some antivirus software (Panda in this case) holds the buffer until the page has finished loaded before sending it to the browser.
If you're still not getting the buffer work correctly then try to clean all the others before starting your own (and even if PHP tells you that there are no buffers active): while(@ob_end_clean());
You must call them in the correct order. ob_flush(); flush();
For some reason, calling just flush or ob_flush or even both together did not get my output buffers flushed, and calling ob_end_flush by itself didn't work either but calling them all worked well. Here is my new output flushing function. Enjoy
As stated in flush() manual entry, if php compresses the ouput with zlib this function may be ineffective. A possible option for folders on your server that have scripts which may take a long time to run is to add the following in your relevant .htaccess file: php_flag zlib.output_compression off php_value max_execution_time 3000 php_value max_input_time 3000
I was having problems with output buffering which seemed to be active by default on the server, although phpinfo said something else.. In any case I needed to know that when I ran ob_start, it would start at the top level, so I could use ob_flush as it's intended without having to call multiple ob_flush in-script - this is what I did: Then I could call ob_flush(); followed by flush(); and get the output I wanted, which I didn't if I started the script with just ob_start(); This was on a windows apache 2 server with php 5.0.4 btw.
Currently I have Chrome on OS X Snow Leopard updating a page as it is sent more data, BUT it only does this after I send it along with 1013 more characters (making 1019 total characters). After it receives this it immediately displays it and then displays anything else as it is received. (Note that this browser-operating system combination isn't necessarily the only one, it's just the only one I've tested.) In order to do this using php, I've done nothing but send ob_flush() after each echo or print. I can also make it happen without ob_flush() by calling ob_implicit_flush(), then ob_end_flush() before print, and then it updates with each print after that. I have pretty typical settings and I change none of them when the file runs, it literally looks like this: [1013 more characters]
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)