2015-06-04 53 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手冊,示例等。如果我錯了,也可能會查找如何執行異步函數調用