php 用sleep(s)来进行停顿,那么小于1秒的停顿怎么弄呢?那就是usleep ,不过,usleep只能在unix(linux)系统下运行哦。
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();
~
数据结果如下
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函数如下
function microtime_float(){
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
更多信息请查看IT技术专栏