Bug #74479 [Opn]: usleep with large numbers

From: Date: Tue, 11 Aug 2020 12:28:30 +0000
Subject: Bug #74479 [Opn]: usleep with large numbers
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228510@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
 Type:               Bug
 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:

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>


Previous Comments:
------------------------------------------------------------------------
[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


Thread (3 messages)

« previous php.bugs (#228510) next »