note 54572 added to function.usleep
| From: | gmc at serveisw3 dot net | Date: | Fri, 08 Jul 2005 04:11:47 +0000 |
| Subject: | note 54572 added to function.usleep | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91626@lists.php.net to get a copy of this message | ||
If you're using Windows then you maybe are in trouble with usleep if you really need to use it.
The Bernie's microdelay function using fsockopen does not work properly, and the fclose
doesn't help much.
I don't know if network connections go strange, but I know it does not work since you've
made more than 2000 - 3000 calls to it, so it's not a reliable solution in 'long
life' php scripts, or these are the issues of the microdelay function in my PHP and PHP-GTK
applications.
Though another solution should be found, and googling a bit I fount a WinAPI function: Sleep.
So I get with this snippet wich works fine for me, you get milliseconds precission but the more
important, it works for long-run scripts and of course, it does not waste any CPU cycles.
dl('php_w32api.dll');
$GLOBALS['win32api'] =& new win32;
// USleep alternative for Windows and PHP4:
$GLOBALS['win32api']->registerfunction("long Sleep (long dwMillisecods) From
kernel32.dll");
// Now you can call the function from everywhere in your script:
$GLOBALS['win32api']->Sleep(milliseconds);
for ($msec = 2000; $msec > 0; $msec = $msec - 125) {
echo "Hi. Next one in $msec msec.\n";
$GLOBALS['win32api']->Sleep($msec);
}
----
Manual Page -- http://www.php.net/manual/en/function.usleep.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54572
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54572&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54572&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54572&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54572&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54572&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54572&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54572&report=yes
Search -- http://master.php.net/manage/user-notes.php