使用PHP如何每隔一定时间回显内容? [英] Using PHP how to echo content every certain amount of time?

查看:50
本文介绍了使用PHP如何每隔一定时间回显内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

echo "1";
sleep(1);

echo "2";
sleep(1);

echo "3";

正在尝试做的是让脚本在屏幕上回显"1",然后等待一秒钟,然后显示"2",以此类推...脚本等待2秒钟,然后一次显示所有内容.我只知道这与缓冲有关

What am trying to do is have the script echo "1" in the screen wait for one second then display "2" etc... As is the script waits for 2 seconds then displays all content at one. All i know about this is that it has do to with buffering

推荐答案

在脚本开始处通过刷新禁用输出缓冲,并激活隐式输出缓冲区刷新.这应该做到:

Disable output buffering by flushing at the beginning of script, and activate implicit output buffer flushing. This should do it:

ob_implicit_flush(true);
ob_end_flush();

for ($i=0; $i<5; $i++) {
   echo $i.'<br>';
   sleep(1);
}

这篇关于使用PHP如何每隔一定时间回显内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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