Hi guys I have a weird question,
I have a cli php script runs on Centos 5.x which uses usleep (somtimes 1sec, somet开发者_运维技巧imes 2sec, somtimes 100ms it depends) if there is some wait required, but what I have noticed its that once on usleep() it seems to use about 40% of idle CPU:
Cpu(s): 5.3%us, 21.3%sy, 0.0%ni, 57.2%id, 0.0%wa, 0.0%hi, 0.0%si, 16.1%st
any ideas ?
cheersThis doesn't happen for me with a very simple testcase. Try the following on your system to see if you still get the excessive CPU time.
Script test.php:
<?php
for ($n=0;$n<1000;$n++)
{
usleep(10);
}
?>
Then at the command line run: time php test.php
My results are as follows:
[ar@arctic ~]$ cat /etc/redhat-release
CentOS release 5.2 (Final)
[ar@arctic ~]$ time php test.php
real 0m1.020s
user 0m0.013s
sys 0m0.006s
You can see that the user and sys time are very very small in comparison to the real (or elapsed) time. i.e. CPU utilisation was very low.
Under Windows systems, if you do not set the time limit of the execution of your script to 0 (set_time_limit(0);
), the php executable will eat as much as 50% CPU power when using sleep or usleep functions.
精彩评论