PHP睡眠延迟 [英] PHP sleep delay
问题描述
for($ i)在PHP中,我希望在循环的每次迭代中放置一些延迟。 = 0; $ i< = 10; $ i ++){
$ file_exists = file_exists($ location。$ filename);
if($ file_exists){
break;
//睡3秒
$ / code $ / pre
使用 PHP sleep()$ c $> 功能。 http://php.net/manual/en/function.sleep.php
这停止给定秒数的下一个循环的执行。 ($ i = 0; $ i< = 10; $ i ++){
(
pre $ $ file_exists = file_exists($位置$文件名。);
if($ file_exists){
break;
}
sleep(3); //每循环3秒钟停止
code $ pre
In PHP, I want to put a number of second delay on each iteration of the loop.
for ($i=0; $i <= 10; $i++) {
$file_exists=file_exists($location.$filename);
if($file_exists) {
break;
}
//sleep for 3 seconds
}
How can I do this?
解决方案 Use PHP sleep()
function. http://php.net/manual/en/function.sleep.php
This stops execution of next loop for the given number of seconds. So something like this
for ($i=0; $i <= 10; $i++) {
$file_exists=file_exists($location.$filename);
if($file_exists) {
break;
}
sleep(3); // this should halt for 3 seconds for every loop
}
这篇关于PHP睡眠延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!