note 94016 added to function.usleep
| From: | adrian dot voica at gmail dot com | Date: | Mon, 12 Oct 2009 14:15:48 +0000 |
| Subject: | note 94016 added to function.usleep | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161651@lists.php.net to get a copy of this message | ||
VERY VERY IMPORTANT!!!
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.
This is an extremely annoying behavior. It took me a lot of time to figure it out. It may have
something to do with the fact that the usleep and sleep are "supervised" by the time limit
set by set_time_limit() which defaults to 30 seconds; --that's just my assumption. I may be
wrong, I am only human ;)
It's quite simple, but the set_time_limit() function is poorly documented at this level.
<?php
set_time_limit(0); // Remove the time limit for command-line usage;
$counter = 0; // Some simple counter;
while ($counter < 100) { // Do nothing for 100*100 miliseconds (10 seconds);
$counter++;
usleep(100000); // Sleep for 100 miliseconds;
}
Good luck!
----
Server IP: 69.147.83.197
Probable Submitter: 89.137.116.105
----
Manual Page -- http://www.php.net/manual/en/function.usleep.php
Edit -- https://master.php.net/note/edit/94016
Del: integrated -- https://master.php.net/note/delete/94016/integrated
Del: useless -- https://master.php.net/note/delete/94016/useless
Del: bad code -- https://master.php.net/note/delete/94016/bad+code
Del: spam -- https://master.php.net/note/delete/94016/spam
Del: non-english -- https://master.php.net/note/delete/94016/non-english
Del: in docs -- https://master.php.net/note/delete/94016/in+docs
Del: other reasons-- https://master.php.net/note/delete/94016
Reject -- https://master.php.net/note/reject/94016
Search -- https://master.php.net/manage/user-notes.php