3
I’m using usleep
to simulate slower internet in my projects, so as to have a better perception of the screens when there are loads for ajax requests for example.
Using a linux environment seems to work normal if use:
usleep(2500);
But in Windows seems to have no effect, the delay does not occur. I know that the usleep
has some problems that can vary for each processor and I even know this alternative php.net#54572:
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);
}
But where I read the problems are related the time differences and processor reaching 100%, but did not find on the function "not work".
I’m using:
- Processor: Interl Core i5 m450 (2.40 Ghz)
- PHP 5.4.12 (Thread Safety)
- Architecture x64
- Server API: Apache 2.0 Handler
Is it a variant processor or PHP version?
It really was a gaffe of mine,
usleep(2000000);
should be right for 2 seconds for example.– Guilherme Nascimento
@Guilhermenascimento, I thought you were doing some more detailed measurement. It would be a comment, but it did not fit and turned response. rs
– Papa Charlie
in my millionth idea was for "thousand", but your comment is the right answer, it was a mistake of mine, since millionth refers to the one who occupies the position of million in a series. : ( sometimes I even cheat myself kkkkkkkk! Thank you very much. If you want to add the explanation about millionth to other "confused" people. Thank you. https://pt.wiktionary.org/wiki/milionésimo
– Guilherme Nascimento
@Guilhermenascimento, the comments complement the responses, the merit is his :)
– Papa Charlie