Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
693 views
in Technique[技术] by (71.8m points)

time - How to pause a script just for a fraction of a second in PHP using the SLEEP() function?

sleep(1);   #waits/sleeps for one second then continue running the script

Q1. How to make this 1/100 of a second? which of these work: 0,01 or 0.01 or .01 ?

Q2. What are alternatives? wait(); or snap(); ?? how do they differ (more/less precise)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Q1. How to make this 1/100 of a second? which of these work: 0,01 or 0.01 or .01 ?

None of the above!

usleep is what you want for fractions of a second. usleep(100000) will sleep for one tenth of one second.

Your other options are time_nanosleep which takes both seconds and freaking nanoseconds (one billion of which are one second), and time_sleep_until, which will sleep until a particular unix timestamp has been reached.

Be aware that your system might not have millisecond resolution, no less nanosecond resolution. You might have trouble sleeping for precisely tiny, tiny amounts of time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...