PHP | usleep( ) Function Last Updated : 19 Jun, 2018 Comments Improve Suggest changes Like Article Like Report The usleep() function in PHP is an inbuilt function which is used to delay the execution of the current script for specific microseconds. It is similar to the sleep() function which delays execution of the current script for a specified number of seconds, unlike the usleep() function which delays the execution for a specified number of microseconds. The number of microseconds is passed as a parameter to the usleep function and it executes the script according to the mentioned delay passed as a parameter. Syntax : usleep(microseconds) Parameters Used: The usleep() function in PHP accepts one parameter microseconds. It is a mandatory parameter which specifies the delay in the execution of the script. Return Value: It does not return any value. Errors and Exceptions: The usleep() function throws an error if the specified number of seconds is negative. The usleep() function call consumes CPU cycles and must be used only if necessary. Sleep() function is a better alternative since it doesn't consume CPU cycles. Examples: Input : echo date('h:i:s'); usleep(2000000); echo date('h:i:s'); Output : 06:53:48 06:53:50 Input : echo date('h:i:s'); usleep(rand(1000000, 5000000)) echo date('h:i:s'); Output : 06:53:48 06:53:52 Below programs illustrate the usleep() function: Program 1: php <?php // displaying time echo date('h:i:s') ; // delaying execution of script for 2 seconds usleep(2000000); // displaying time again echo date('h:i:s'); ?> Output: 06:53:48 06:53:50 Program 2: php <?php // displaying time echo date('h:i:s') ; // using rand() function to randomly choose a // value and delay execution of the script usleep(rand(1000000, 5000000)) // displaying time again echo date('h:i:s'); ?> Output: 06:53:48 06:53:52 Reference :http://php.net/manual/en/function.usleep.php Comment More infoAdvertise with us Next Article PHP | usleep( ) Function S Shubrodeep Banerjee Follow Improve Article Tags : Misc Web Technologies PHP PHP-date-time Practice Tags : Misc Similar Reads PHP | sleep( ) Function The sleep() function in PHP is an inbuilt function which is used to delay the execution of the current script for a specified number of seconds. The sleep( ) function accepts seconds as a parameter and returns TRUE on success or FALSE on failure. If the call is interrupted by a signal, sleep() funct 2 min read PHP strlen() Function The strlen() is a built-in function in PHP which returns the length of a given string.It calculates the length of the string including all the whitespaces and special characters. Syntax:strlen($string);Parameters: This parameter represents the string whose length is needed to be returned. Return Val 1 min read PHP | urldecode() Function The urldecode() function is an inbuilt function in PHP which is used to decode url that is encoded by the encode () function. Syntax:string urldecode( $input )Parameters: This function accepts a single parameter $input which holds the url to be decoded. Return Value: This function returns the decode 1 min read PHP urlencode() Function The urlencode() function is an inbuilt PHP function used to encode the URL. This function returns a string consisting of all non-alphanumeric characters exceptâ_. It is replaced by the percent (%) sign, followed by two hex digits and spaces encoded as plus (+) signs. Syntax:string urlencode( $input 1 min read PHP pos() Function The pos() is an inbuilt function in PHP which is used to return the value of the element in an array which the internal pointer is currently pointing to. The pos() function does not increment or decrement the internal pointer after returning the value. In PHP all arrays have an internal pointer. Thi 2 min read Like