php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74479 usleep with large numbers
Submitted: 2017-04-20 14:32 UTC Modified: -
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:
Status: Open 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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Oct 20 09:01:26 2019 UTC