note 119766 added to function.usleep
| From: | moccalotto at gmail dot com | Date: | Sat, 20 Aug 2016 08:43:35 +0000 |
| Subject: | note 119766 added to function.usleep | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206336@lists.php.net to get a copy of this message | ||
usleep() only supports 32-bit signed integers.
This means it can only sleep for 2^31 microseconds. (about 35 minutes).
It does not emit an error or warning if the number is too large. It simply wraps the int around.
This causes unexpected behavior. Attempting to sleep for 24 hours causes the script to sleep for
about 8.34 minutes. ( ((24*3600000000) % (2**31)) / 60000000 )
Tested on PHP 5.3, 5.5, 5.6 and 7.0 on OSX and linux.
<?php
//Sleep that works:
usleep((int) pow(2, 30));
// sleep that does NOT work because wrap-around to negative int:
usleep((int) pow(2, 32)); // applies to any power > 32 as well.
----
Server IP: 72.52.91.14
Probable Submitter: 87.48.139.251
----
Manual Page -- http://php.net/manual/en/function.usleep.php
Edit -- https://master.php.net/note/edit/119766
Del: integrated -- https://master.php.net/note/delete/119766/integrated
Del: useless -- https://master.php.net/note/delete/119766/useless
Del: bad code -- https://master.php.net/note/delete/119766/bad+code
Del: spam -- https://master.php.net/note/delete/119766/spam
Del: non-english -- https://master.php.net/note/delete/119766/non-english
Del: in docs -- https://master.php.net/note/delete/119766/in+docs
Del: other reasons-- https://master.php.net/note/delete/119766
Reject -- https://master.php.net/note/reject/119766
Search -- https://master.php.net/manage/user-notes.php