|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53297 gettimeofday implementation in php/win32/time.c can return 1mil usecs.
Submitted: 2010-11-12 11:31 UTC Modified: 2010-11-12 19:37 UTC
From: ped at 7gods dot org Assigned: cataphract (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 5.3.3 OS: Win32
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: ped at 7gods dot org
New email:
PHP Version: OS:


 [2010-11-12 11:31 UTC] ped at 7gods dot org
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;

Doing >= would be more correct, like this:
                    if (time_Info->tv_usec >= 1000000) {
                        time_Info->tv_usec -= 1000000;

(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 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:
$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).


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-12 19:37 UTC]
Automatic comment from SVN on behalf of cataphract
Log: - Fixed bug #53297 (gettimeofday implementation in php/win32/time.c can return
  1 million microsecs). (ped at 7gods dot org)
- Moved line out of order in NEWS.
 [2010-11-12 19:38 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cataphract
 [2010-11-12 19:38 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 17 22:01:26 2024 UTC