如何在 PHP 中设置计时器?

发布于 2024-08-10 05:08:05 字数 485 浏览 3 评论 0原文

例如,我的目标是测试此处给出的代码:

报告进度的 PHP 脚本to Client

<?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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

抚你发端 2024-08-17 05:08:05

sleep() 会等你。真是太好了。 :)

sleep() will wait for you. It's so nice. :)

你的笑 2024-08-17 05:08:05

请参阅睡眠

int sleep (int $seconds)
将程序执行延迟给定的秒数。

因此,您的 waitalittle 函数可能如下所示:

function waitalittle() {
  sleep(5);
}

See sleep:

int sleep ( int $seconds )
Delays the program execution for the given number of seconds.

So your waitalittle function could look like this:

function waitalittle() {
  sleep(5);
}
懒的傷心 2024-08-17 05:08:05
<?php
sleep(5);
echo 'Task one finished';
flush();

sleep(5);
echo 'Task two finished';
flush();

?>
<?php
sleep(5);
echo 'Task one finished';
flush();

sleep(5);
echo 'Task two finished';
flush();

?>
兮颜 2024-08-17 05:08:05

你可以使用它来代替 waitalittle()

sleep(5);

或以你的方式

function waitalittle() {
sleep(5);
}

you can use this instead of waitalittle()

sleep(5);

or else in your way it is

function waitalittle() {
sleep(5);
}
岁吢 2024-08-17 05:08:05

睡觉();将程序执行延迟给定的秒数。

sleep(int $seconds): int

例如

sleep(5); //Delay for 5 seconds

Sleep(); Delays the program execution for the given number of seconds.

sleep(int $seconds): int

e.g.

sleep(5); //Delay for 5 seconds
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文