如何在 PHP 中设置计时器?
例如,我的目标是测试此处给出的代码:
<?php
waitalittle();
echo 'Task one finished';
flush();
waitalittle();
echo 'Task two finished';
flush();
?>
我的目标是创建 waitalittle() 函数,该函数执行需要 5 秒。
我的最终目标是能够在浏览器中查看 PHP 脚本各个部分的进度,而无需刷新。
我现在遇到的问题是,如果我使用任何旧函数而不是“waitalittle”,所有回显的语句都会同时出现。我想测试上面提到的链接/答案,看看语句在处理时是否在浏览器上回显。
For example, my goal is to test the code given here:
PHP script that reports progress to Client
<?php
waitalittle();
echo 'Task one finished';
flush();
waitalittle();
echo 'Task two finished';
flush();
?>
My objective is to create the waitalittle() function, which should take 5 seconds to execute.
My final goal is to be able to view the progress of various parts of my PHP script in the browser without having to refresh.
The issue I'm having now is that if I use any-old function instead of "waitalittle", all the echoed statements appear at the same time. I want to test the above mentioned link/answer to see if statements are echoed on the browser as they are processed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
sleep() 会等你。真是太好了。 :)
sleep() will wait for you. It's so nice. :)
请参阅
睡眠
:因此,您的
waitalittle
函数可能如下所示:See
sleep
:So your
waitalittle
function could look like this:你可以使用它来代替 waitalittle()
或以你的方式
you can use this instead of waitalittle()
or else in your way it is
睡觉();将程序执行延迟给定的秒数。
sleep(int $seconds): int
例如
Sleep(); Delays the program execution for the given number of seconds.
sleep(int $seconds): int
e.g.