|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #74479 usleep with large numbers
Submitted: 2017-04-20 14:32 UTC Modified: 2021-03-03 13:40 UTC
Avg. Score:2.0 ± 1.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: korchasa at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 5.6.30 OS: Ubuntu 16.04.2 with 4.8.0-46
Private report: No CVE-ID: None
 [2017-04-20 14:32 UTC] korchasa at gmail dot com
usleep works strange on large numbers

Test script:
$start = microtime(true);
usleep(4294967296 + 1000000);
echo round(microtime(true) - $start);

Expected result:
12h pause and 4296 in output or error message

Actual result:
1 second pause and 1 in output


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-20 15:00 UTC]
This is a 32-bit integer overflow issue, it will happen regardless of platform because there is an explicit (unsigned int) cast when the underlying usleep(3) is called.

I would argue that you shouldn't use usleep() to sleep for that kind of time anyway - if you are sleeping for 12 hours, sub-second precision doesn't really matter and is not reasonable to expect.

However in 64-bit environments the expected behaviour could be emulated.
 [2020-08-11 12:28 UTC]
While usleep() has been removed from POSIX.1-2008,
formerly that standard has been mandated that[1]

| The useconds argument shall be less than one million.


| The usleep() function may fail if:
|   The time interval specified one million or more microseconds.

So a general emulation for larger intervals is out of scope.
Changing to doc issue.

[1] <>
 [2020-08-11 12:34 UTC]
-Type: Bug +Type: Documentation Problem
 [2021-03-03 13:40 UTC]
Automatic comment on behalf of
Log: Fix #74479: usleep with large numbers
 [2021-03-03 13:40 UTC]
-Status: Open +Status: Closed
 [2021-03-03 13:40 UTC]
-Assigned To: +Assigned To: cmb
 [2021-03-04 11:17 UTC]
Automatic comment on behalf of
Log: Fix #74479: usleep with large numbers
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Mar 09 08:01:24 2021 UTC