有没有办法使脚本执行时逐步输出PHP? [英] Is there a way to make PHP progressively output as the script executes?

查看:234
本文介绍了有没有办法使脚本执行时逐步输出PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在编写一次性脚本供个人个人使用,我希望能够看到该过程的进展情况.基本上,我正在处理数千个媒体版本,并将它们发送到我们的新CMS.

So I'm writing a disposable script for my own personal single use and I want to be able see how the process is going. Basically I'm processing a couple of thousand media releases and sending them to our new CMS.

因此,我不会敲打CMS,每5个请求后,我就会将脚本sleep制作几秒钟.

So I don't hammer the CMS, I'm making the script sleep for a couple of seconds after every 5 requests.

我希望-在脚本执行时-能够看到我的echo告诉我脚本正在休眠或与Web服务的最后一次交易成功.

I would like - as the script is executing - to be able to see my echos telling me the script is going to sleep or that the last transaction with the webservice was successful.

这在PHP中可行吗?

感谢您的帮助!

伊恩

推荐答案

使用ob_flush发送缓冲区中的任何数据.因此,您可以执行一些命令,刷新输出,然后在处理更多命令之前先休眠一会儿.

Use ob_flush to send any data in the buffer. So you can execute some commands, flush the output, and then sleep for a bit before processing more commands.

我确实注意到,在脚本特别长的情况下,PHP似乎开始发送缓冲区中的内容,即使脚本尚未完成执行

I do notice that on particularly long scripts, PHP seems to start sending what it's got in the buffer even though the script hasn't finished executing

默认情况下,在整个脚本执行完毕之前,PHP永远不会回显任何内容.那只是您的浏览器试图一次输出太多数据,或者您的某些东西导致其刷新到某处.

By default, PHP will never echo anything until the entire script finishes executing. That's just your browser trying to output way too much data at once, or you have something that's causing it to flush somewhere.

这篇关于有没有办法使脚本执行时逐步输出PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆