php 用sleep(s)來進(jìn)行停頓,那么小于1秒的停頓怎么弄呢?那就是usleep ,不過,usleep只能在unix(linux)系統(tǒng)下運行哦。
echo "\n\rsleep begin:".microtime_float();
sleep(1);
echo "\n\rsleep 1 s:".microtime_float();
sleep(2);
echo "\n\rsleep 2 s:".microtime_float();
//
echo "\n\rusleep begin:".microtime_float();
usleep(50*1000);
echo "\n\rusleep 50 ms:".microtime_float();
usleep(990*1000);
echo "\n\rusleep 990 ms:".microtime_float();
~
數(shù)據(jù)結(jié)果如下
sleep begin:1381225780.5979
sleep 1 s:1381225781.5991
sleep 2 s:1381225783.6
usleep begin:1381225783.6
usleep 50 ms:1381225783.651
usleep 990 ms:1381225784.6419
microtime_float函數(shù)如下
function microtime_float(){
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
更多信息請查看IT技術(shù)專欄