php.net |  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
Votes:2
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: korchasa at gmail dot com
New email:
PHP Version: OS:

 

 [2017-04-20 14:32 UTC] korchasa at gmail dot com
Description:
------------
usleep works strange on large numbers

Test script:
---------------
<?php
$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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-20 15:00 UTC] daverandom@php.net
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. https://lxr.room11.org/xref/php-src%40master/ext/standard/basic_functions.c#4520

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] cmb@php.net
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.

and

| The usleep() function may fail if:
| [EINVAL]
|   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] <https://pubs.opengroup.org/onlinepubs/009695399/functions/usleep.html>
 [2020-08-11 12:34 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2021-03-03 13:40 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=95bc76b545a00d436239af6d5516f75ff890df56
Log: Fix #74479: usleep with large numbers
 [2021-03-03 13:40 UTC] cmb@php.net
-Status: Open +Status: Closed
 [2021-03-03 13:40 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2021-03-04 11:17 UTC] mumumu@php.net
Automatic comment on behalf of mumumu@mumumu.org
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=4d160b3c8f758f6b14a39b8ed1f2b378ee511bd7
Log: Fix #74479: usleep with large numbers
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 15:01:28 2024 UTC