PHP sleep delay

前端 未结 5 708
心在旅途
心在旅途 2020-12-14 06:52

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.$filenam         


        
5条回答
  •  太阳男子
    2020-12-14 07:16

    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
    }
    

提交回复
热议问题