usleep is not working on Windows

3

I'm using usleep to simulate slower internet in my projects, so to have a better perception of the screens when there is loads for ajax requests for example.

Using a linux environment seems to work normal if I use:

usleep(2500);

But in Windows seems to have no effect, the delay does not occur. I know that usleep has some problems that may vary for each processor and I even know of this alternative mentioned in the 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 to the differences in time and processor reaching 100%, but I did not find out about the "not working" function.

I'm using:

  • Processor: Interl Core i5 m450 (2.40 GHz)
  • PHP 5.4.12 (Thread Safety)
  • x64 Architecture
  • Server API: Apache 2.0 Handler

Is it a processor variation or the PHP version?

    
asked by anonymous 08.08.2015 / 01:35

1 answer

2

According to DOC, usleep - Delays execution in millionth of a second , so usleep(2500) may be inconspicuous in the simulation test you are doing. Maybe precision is not 100% working with millionth of a second , but here usleep(2500) works correctly.

echo microtime(1)
usleep(2500)
echo microtime(1)

1439005351.1457
1439005351.1487

The only bug reference reported in the Windows environment I found was, Function usleep does not work under Windows , and in my opinion, it is a mistake to use usleep (500) and expect a delay of 1/2 second .

    
08.08.2015 / 05:52