Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting PHP timer based functions

Tags:

php

timer

I have a php file test.php. I want to echo or print "Success" after 5 seconds, soon after the php file is called or loaded or opened by the browser. Incidentally, sometimes I may want to execute / initialise some functions after a specific interval of time.

How can I make a time-oriented task using php, like printing a message after 5 seconds?

like image 604
Alfred Avatar asked Dec 21 '22 12:12

Alfred


1 Answers

You can interrupt the execution of your script using sleep(). If you want sub-second precision, you can use usleep():

# wait half a second (500ms)
usleep(500000);
echo 'Success';
like image 73
soulmerge Avatar answered Dec 24 '22 00:12

soulmerge