- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个需要几分钟才能完成处理的 PHP 脚本。当页面仍在加载时,我想在可用时显示部分 PHP 输出,这可以使用 ob_start()
和 ob_flush()
来完成。
在整个脚本执行完毕后,我想从一开始就将所有 PHP 输出保存到一个 HTML 文件中。这可以使用 ob_start()
和 file_put_contents("log.html", ob_get_contents());
问题:但是,因为我们一直在调用 ob_flush()
,所以出现了用 file_put_contents()
保存的最终文件分成不同的文件。我怀疑这与在调用 file_put_contents()
之前调用 ob_start()
清除缓冲区有关,但为什么它不只是保存最终之间的输出ob_flush()
和 file_put_contents()
到文件,而是保存几个不同的文件? (我可能错了,单独的部分文件可能是由于脚本的部分执行)
换句话说,如何在执行长脚本时显示 PHP 输出,并将所有 PHP 输出保存到单个 HTML 文件中?
PHP 代码
// Start the buffering
ob_start();
......
ob_flush();
......
ob_flush();
......
file_put_contents("log.html", ob_get_contents());
最佳答案
我能想到的几种方法:
保留一个变量(称为 $content 之类的东西),并在每次调用 ob_flush() 时追加当前缓冲区:
$content = '';
...
$content .= ob_get_contents();
ob_flush();
...
$content .= ob_get_contents();
ob_flush();
...
file_put_contents('log.html', $content . ob_get_contents());
ob_flush();
使用 fopen():
$fp = fopen('log.html', 'w+');
...
fwrite($fp, ob_get_contents());
ob_flush();
...
fwrite($fp, ob_get_contents());
ob_flush();
...
fwrite($fp, ob_get_contents());
fclose($fp);
ob_flush();
关于php - ob_flush 不丢弃缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8136685/
我有一个需要几分钟才能完成处理的 PHP 脚本。当页面仍在加载时,我想在可用时显示部分 PHP 输出,这可以使用 ob_start() 和 ob_flush() 来完成。 在整个脚本执行完毕后,我想从
当我在本地主机(通过 MAMP)上调用 PHP 的 ob_flush() 函数时,出现以下错误: Notice: ob_flush() [ref.outcontrol]: failed to flus
在我的网站(使用 drupal 运行)中,ob_flush 函数需要很长时间(在 10 - 100 秒之间)才能执行。我如何找出原因?是什么导致了这么长时间? 最佳答案 试试这个: ob_start(
我正在使用 iframe 方法编写文件上传脚本。在后端,文件上传后,脚本还做了一些事情。因此,一旦文件上传,我就会将输出刷新到浏览器(进入 iframe),然后脚本继续。从 Chrome 控制台我可以
我正在用 PHP 编写一个应用程序,我决定自己做一些测试以确定 PHP 处理缓冲区和缓冲的能力。具体来说,我想看看手动调用 ob_start() 和 ob_flush() 是否会对我的程序产生巨大影响
我已经尝试了几次尝试让我的 flush 和 ob_flush 工作。我试过设置 ini 以允许缓冲,我试过使用我在网上找到的几个不同的函数来进行输出缓冲,但没有一个起作用。该脚本想要等到它完全完成,直
有关php的ob_flush()与flush()使用方法 注意:ob_flush()和flush()这两个函数一般要一起使用,顺序是先ob_flush(),然后flush(),它们的作用是刷新缓冲
flush()、ob_flush()、ob_end_flush()三者的区别: 首先,说下buffer,它是一个内存地址空间,为4096(1kb)【在php.ini配置文件中找到output_bu
我遇到了 PHP ob_flush(); 的问题 似乎它只在 IE10 中不起作用。 gzip 和缓存在服务器上被禁用,它在除 IE10 之外的任何地方都有效。 如果有人知道如何解开这个谜团,我将不胜
我有以下 PHP 脚本: "; ob_flush(); flush(); sleep(1); } ob_end_flush(); ?> 它在 WAMP 本地主机上工作正常并且每
我对 PHP 函数 ob_flush() 和 ob_end_flush() 感到困惑。关于函数 ob_flush manual说 The buffer contents are discarded a
如果我从 XAMPP 上的本地服务器在 chrome 中加载此脚本: header("Content-Type:text/plain"); set_time_limit(0); $max = 40;
我刚看完this post The loading time of webpages is improved by enabling gzip compression on server. Bette
ob_clean() 和 ob_flush() 有什么区别? 此外,ob_end_clean() 和 ob_end_flush() 之间有什么区别?我知道 ob_get_clean() 和 ob_ge
ob_flush() 和 flush() 有什么区别,为什么必须同时调用? ob_flush() reference说: This function will send the contents of
我的意思是...让我们只发出一个 AJAX 请求并将结果插入到 div#result 中.. 在后端,脚本使用ob_flush() 发送 header 但不会终止请求,直到它终止(使用exit 或ob
嗨请查看以下代码: \n"; for( $i = 0 ; $i \n"; ob_flush(); flush(); sleep(1); } echo "End ...\n";
我正在使用 ob_start()/ob_flush(),希望在长时间的导入操作中给我一些进展。 这是我正在做的事情的简单概述: "; $conn = ftp_connect($ftp_site) or
搜索了很多,但找不到太多关于这个的信息.. 我有一个通过循环处理很多事情的页面,我把它放在 php 页面的顶部: ob_implicit_flush(true); ob_end_flush(); 这很
像下面这样在 php 中进行错误处理是否可以接受?我对ob_start()/ob_clean()/ob_flush()不是很熟悉,所以我想知道使用它们有什么不好的影响吗?例如,它们会影响性能吗?
我是一名优秀的程序员,十分优秀!