Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

usleep() Validates Its Microseconds Argument Range

usleep()’s $microseconds argument is passed to the operating system as an unsigned integer. Until PHP 8.6, a value greater than UINT_MAX (4294967295) silently overflowed, which could make the function sleep for a much shorter time than requested. In PHP 8.6, a value greater than UINT_MAX throws a ValueError instead.

PHP code

<?php

try {
    var_dump(usleep(4294967296));
} catch (\ValueError $e) {
    echo "ValueError: ".$e->getMessage()."\n";
}

?>

Before

NULL

After

ValueError: usleep(): Argument #1 ($microseconds) must be between 0 and 4294967295

PHP version change

This behavior changed in 8.6.

See Also

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat