From:             master_tip at hotmail dot com
Operating system: Windows 2000 Sp4
PHP version:      5.0.3
PHP Bug Type:     Unknown/Other Function
Bug description:  usleep still not working correctly

Description:
------------
usleep can be very usefull for slowing loops and prevent them from using
to much cpu but this usleep does not just slow is almost stops no mather
what value you give it.

look at included reproduce code, i run it as cgi but should be the same
results from web or other interface.

here is a test loop of 10000 loops. wich takes on my pc 6ms to complete
without usleep. now here comes the strange things.

when i remove usleep it runs in 6ms
when i include usleep but set it to zero it takes 90ms
logical since it still makes the call.

but when i set usleep to 1 microsecond it takes 99sec to complete. a
massive increase but okay. now when i set it 
to 1000, it still takes 99sec. although the usleep has multiplied factor
1000 it seems to have no effect. 

and when i increase to 2000 still no effect
not until i set it till 100.000 it has effect. 
it now takes 1000sec(16min) to complete. yes i did lower the  loops to 100
and multiplied the time by 100000 to stay in the same scale.) so the time
increased by a factor 10 but the usleep only by a factor 1. and between 1
and 100.000 no diffrence wich is equal to a precision of 100ms, so it does
not accept microseconds at all except zero. at a delay of 500000
microseconds the total of 10000 loops took 5000 seconds.

so usleep works more like sleep(0.1) instead of usleep(1000) wich would be
sleep(0.01);. there was a bug report earlier from php version 5.0.0 where
it was said closed since new cvs snapshot contained the fix. now in php
version 5.0.3 usleep still does not work, at least not wich microseconds
or milisecond but deciseconds. 

also what if usleep read deciseconds instead of microseconds. because
100000 deciseconds is 100 seconds. 

should be time to get this fixed or removed it from documentation for a
later point to be added again.

hope this would help in fixing this problem, especialy for gtk apps its
important that php does not use 100% cpu. its not a full-screen game or
something.

ps. actual times can be diffrent but its ofcourse about the scale not
being correct. 

greetings from holland,
 Docey.


Reproduce code:
---------------
<?php
// get starting time
$start_time_raw = microtime();
$rounds = 0;

// make some loops
while($rounds != 10000){
 $rounds++;
 usleep(0);
}
 // note the quit time
 $end_time_raw = microtime();

 // process time between start and end.
 list($end_time, $end_stime) = split(" ", $end_time_raw, 2);
 list($start_time, $start_stime) = split(" ", $start_time_raw, 2);

 $dif_time = 0;

 if($start_stime < $end_stime){
  $dif_time       = $end_stime - $start_stime;  
 }else{
  if($end_time < $start_time){
   $dif_time = 1;
  }
 }

 $end_time_calc = $end_time + $dif_time;  
 $run_time = $end_time_calc - $start_time;
 $ms_time  = $run_time * 1000;

// print actual results
print("\n\n total run time ".$ms_time." miliseconds \n\n
=>STR:".$start_time_raw."\n =>END:".$end_time_raw."\n
=>RUN:".$run_time."\n =>DIF:".$dif_time);

?>

Expected result:
----------------
that when the usleep increases by factor 10 the time to run would also
increase by a factor 10 since there is no other delay in between.

like running a loop of 10 times sleep(1) wich would be the same as running
10 times usleep(1000000).

Actual result:
--------------
usleep does not responds on values below 100ms(100000microseconds) and
acts like sleep(0.1).


-- 
Edit bug report at http://bugs.php.net/?id=32203&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=32203&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=32203&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=32203&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=32203&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=32203&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=32203&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=32203&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=32203&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=32203&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=32203&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=32203&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=32203&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=32203&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=32203&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=32203&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=32203&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=32203&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=32203&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=32203&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=32203&r=mysqlcfg

Reply via email to