如果满足条件,命令休眠暂停20秒 [英] Command sleep to pause for 20 seconds if condition is met
本文介绍了如果满足条件,命令休眠暂停20秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要执行以下操作:如果$Start是28的倍数,则脚本将暂停20秒,然后继续工作。
为此我写道:
set_time_limit(0);
ini_set('display_errors', 1);
error_reporting(E_ALL);
date_default_timezone_set("Europe/Moscow");
$start = 0;
$end = 2000;
for($start = 0; $start < 20; $start++){
if($start % 28 == 0){sleep(20);echo 'sleep ';}
echo date('H:i:s').'<br>';
}
当我使用它时,我得到:
sleep 14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
14:51:01
这样我就可以看到脚本运行不正常...
您能告诉我为什么脚本不能正常工作吗?
推荐答案
我看到循环:
for($start = 0; $start < 20; $start++){
if($start % 28 == 0){sleep(20);echo 'sleep ';}
echo date('H:i:s').'<br>';
和循环20中的最后一个值元素$Start。
对于更多循环,1需要使用值$Start56,因为if($start % 28 == 0)
。
例如-28*2 //for 2 loop.
这篇关于如果满足条件,命令休眠暂停20秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文