From: Operating system: Win32 PHP version: 5.3.3 Package: Unknown/Other Function Bug Type: Bug Bug description:gettimeofday implementation in php/win32/time.c can return 1mil usecs.
Description: ------------ in source file php/win32/time.c in function PHPAPI int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Info) toward end (L108 in 5.3.3 sources) there is this block of code: if (time_Info->tv_usec > 1000000) { time_Info->tv_usec -= 1000000; ++time_Info->tv_sec; } Doing >= would be more correct, like this: if (time_Info->tv_usec >= 1000000) { time_Info->tv_usec -= 1000000; ++time_Info->tv_sec; } (for most of the gettimeofday usage this is very minor bug, but while profiling with xdebug extension on windows platform this does expose the xdebug bug http://bugs.xdebug.org/view.php?id=357 which together leads to garbage profiling results) Attached script does expose the problem also trough PHP (it fails at my machine quite regularly, shouldn't take more then 2-3 runs to catch it). Test script: --------------- <?php $safety_counter = 0; do { $t = gettimeofday(); } while( $t['usec'] < 1000000 && $safety_counter++ < 1000000 ); if ( $t['usec'] == 1000000 ) { echo '<pre>', print_r( $t, TRUE ), '</pre>'; die('Returned gettimeofday array contains 1mil+ of microseconds (which is 1second)!'); } echo 'The gettimeofday didn\'t produce wrong value (tried it 1mil times). Try again!'; ?> Expected result: ---------------- The returned $t['usec'] should never contain value >= 1000000, so the script should always end with final echo. Actual result: -------------- $t['usec'] == 1000000 occasionally (on my machine at least once per 5 runs of script). -- Edit bug report at http://bugs.php.net/bug.php?id=53297&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53297&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53297&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53297&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53297&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53297&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53297&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53297&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53297&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53297&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53297&r=support Expected behavior: http://bugs.php.net/fix.php?id=53297&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53297&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53297&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53297&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53297&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53297&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53297&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53297&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53297&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53297&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53297&r=mysqlcfg