Tags
PHP , HTML , regex
Asked 2 years ago
20 Jan 2022
Views 830
jagdish

jagdish posted

how to delay execution in php ?


foreach($code as $c){
// run some code

// delay execution for some second before continuing to execution 
}


I want to put some delay code in PHP.

sandip

sandip
answered Jan 20 '22 00:00

use sleep() function, which can be used to delay in execution in PHP.

foreach( .. ){
// sleep for 5 seconds
sleep(5);
}

sleep(5), it program will sleep for 5 seconds in every iteration of foreach loop
pratik

pratik
answered Jan 20 '22 00:00

you can delay execution in PHP for nanosecond as well with time_nanosleep() function .
time_nanosleep — Delay for a number of seconds and nanoseconds

time_nanosleep(int $seconds, int $nanoseconds) :
you can delay execution with second and nanoseconds combination .


time_nanosleep(0,5) -- will delay execution for 5 nanoseconds .

Post Answer