2015-06-04 36 views
0

我有一个php while循环,每5秒钟发送3个随机数,每个数字用sleep(5)函数。如何在X时间中断/暂停循环,然后再次启动相同的循环?

我想要的是,当第一个循环结束时,我想打破它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); 

在这里我想暂停循环60秒,我不想使用睡眠功能暂停;我想使用类似break的东西来停止循环,并在60秒后再次启动它。

我已经使用cli任务来启动代码。

+0

您是如何开始您的代码的?它的cli任务还是来自浏览器? –

+0

我在任务 – Su1raM

+0

中启动代码什么原因,您不想使用'sleep'? –

回答

0

我想这可能成为可能使用PHP threads。请参阅PHP手册,示例等。如果我错了,也可能会查找如何执行异步函数调用