Bug #74479 [Com]: usleep with large numbers

From: Date: Thu, 20 Apr 2017 15:00:39 +0000
Subject: Bug #74479 [Com]: usleep with large numbers
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-208684@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
 Comment by:         daverandom@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:

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.


Previous Comments:
------------------------------------------------------------------------
[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 (#208684) next »