Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何中断/暂停循环X次,然后再次启动相同的循环?_Php_While Loop_Break - Fatal编程技术网

Php 如何中断/暂停循环X次,然后再次启动相同的循环?

Php 如何中断/暂停循环X次,然后再次启动相同的循环?,php,while-loop,break,Php,While Loop,Break,我有一个phpwhile循环,它使用sleep(5)函数在5秒内从5发送三个随机数 我想要的是,当第一个循环结束时,我想中断它60秒,然后再次开始相同的循环 $i= 1 do{ $one = mt_rand(1, 99); $two = mt_rand(1, 99); $three = mt_rand(1, 99); $this->SendMessage( 'Number: '.$one.'' ); sleep(5); $this->s

我有一个php
while
循环,它使用
sleep(5)
函数在5秒内从5发送三个随机数

我想要的是,当第一个循环结束时,我想中断它60秒,然后再次开始相同的循环

$i= 1
do{
    $one = mt_rand(1, 99);
    $two = mt_rand(1, 99);
    $three = mt_rand(1, 99);
    $this->SendMessage( 'Number: '.$one.'' );
    sleep(5);
    $this->sendMessage( 'Number: '.$two.'' );
    sleep(5);
    $this->sendMessage( 'Number: '.$three.'' );
    sleep(5);
    $this->SendMessage( 'The three random numbers has been send, another three numbers will be show in 60 seconds.' );
    $i++;
}
while ($i<100);
$i=1
做{
$1=百万兰特(1,99);
$2=百万兰特(1,99);
$3=百万兰特(1,99);
$this->SendMessage('Number:'.$one');
睡眠(5);
$this->sendMessage('Number:'.$two');
睡眠(5);
$this->sendMessage('Number:'.$three');
睡眠(5);
$this->SendMessage('三个随机数已发送,另三个随机数将在60秒内显示');
$i++;
}

虽然($i我想使用可能会成为可能。请参阅PHP手册、示例等。如果我错了,您还可以查看如何执行异步函数调用

您是如何启动代码的?它的cli任务还是从浏览器?我在任务中启动代码什么原因,您不想使用
睡眠
?因为我想进行一些更新,并且If处于睡眠状态php在这个时候什么也做不了。。