note 72010 added to function.usleep

From: Date: Thu, 28 Dec 2006 22:16:28 +0000
Subject: note 72010 added to function.usleep
Groups: php.notes 
Request: Send a blank email to php-notes+get-120991@lists.php.net to get a copy of this message
I have no idea why nobody came up with this yet, but there is an efficient way to reproduce usleep() under windows: <?php function usleep_win($msec) { $usec = $msec * 1000; socket_select($read = NULL, $write = NULL, $sock = array(socket_create (AF_INET, SOCK_RAW, 0)), 0, $usec); } ?> * Doesnt busy wait * Doesnt eat memory * Works for millions of repetitions * Seems to be rather efficient It seems that the average error (on my machine) is about 5ms (it sleeps 5ms more than intended) thats probably due to code execution as well as kernel timers. A socket without any purpose is highly unlikely to every cause an exception, so socket_select will always sleep until the timeout is hit. ---- Server IP: 66.163.161.117 Probable Submitter: 84.167.158.241 ---- Manual Page -- http://www.php.net/manual/en/function.usleep.php Edit -- https://master.php.net/note/edit/72010 Del: integrated -- https://master.php.net/note/delete/72010/integrated Del: useless -- https://master.php.net/note/delete/72010/useless Del: bad code -- https://master.php.net/note/delete/72010/bad+code Del: spam -- https://master.php.net/note/delete/72010/spam Del: non-english -- https://master.php.net/note/delete/72010/non-english Del: in docs -- https://master.php.net/note/delete/72010/in+docs Del: other reasons-- https://master.php.net/note/delete/72010 Reject -- https://master.php.net/note/reject/72010 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120991) next »