note 10337 added to usleep
| From: | dave at techweavers dot net | Date: | Fri, 29 Dec 2000 00:29:46 +0000 |
| Subject: | note 10337 added to usleep | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-9168@lists.php.net to get a copy of this message | ||
Whoops mad a few mistakes here is a better function:
function phpmon($max)
{
$cmd =
ps -Unobody -r -o%cpu;
$lines = explode("\n", $cmd);
$usage = substr($lines[1], 0, strpos($lines[1], "."));
$sleeprate = 500;
while ($usage >= $max)
{
$cmd = ps -Unobody -r -o%cpu;
$lines = explode("\n", $cmd);
$usage = substr($lines[1], 0, strpos($lines[1], "."));
usleep($sleeprate);
}
}
I have noticed that this consumes a lot of system CPU (at least in my limited testing) possibly from
all of the system calls or the huge mathematical functions I used to test the effectiveness of the
script.
http://www.php.net/manual/function.usleep.php