Doc #74479 [Opn->Csd]: usleep with large numbers
| From: | cmb@php.net | Date: | Wed, 03 Mar 2021 13:40:33 +0000 |
| Subject: | Doc #74479 [Opn->Csd]: usleep with large numbers | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-18613@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74479&edit=1
ID: 74479
Updated by: cmb@php.net
Reported by: korchasa at gmail dot com
Summary: usleep with large numbers
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Unknown/Other Function
Operating System: Ubuntu 16.04.2 with 4.8.0-46
PHP Version: 5.6.30
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2020-08-11 12:28:30] 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>
------------------------------------------------------------------------
[2017-04-20 15:00:32] 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.
------------------------------------------------------------------------
[2017-04-20 14:32:05] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74479&edit=1