note 119766 rejected from function.usleep by cmb

From: Date: Sat, 20 Aug 2016 09:35:37 +0000
Subject: note 119766 rejected from function.usleep by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-206338@lists.php.net to get a copy of this message
Note Submitter: moccalotto at gmail dot com ---- 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.

« previous php.notes (#206338) next »