Introduction
In this article I describe the PHP Miscellaneous functions sleep, time_nanosleep, time_sleep_until, uniqid, unpack and usleep. To learn some other FileSystem functions, go to:
PHP sleep() Function
The PHP Miscellaneous sleep function delays execution of the current script for a specified number of seconds and it returns zero on success or false on error.
Syntax
| sleep(seconds) |
Parameter in sleep function
The parameter of the function is:
| Parameter | Description |
| seconds | It specifies the number of seconds to delay the script. |
Example
An example of the function is:
<?php
print_r(date('h:i:s'));
sleep(10);
echo "</br>";
print_r(date('h:i:s')); // it prints after 10 seconds time.
?>
Output
PHP time_nanosleep() Function
The PHP Miscellaneous time_nanosleep function delays execution for a specified number of seconds and nanoseconds and this function returns true on success or false on failure.
Syntax
| time_nanosleep(seconds,nanoseconds) |
Parameter in time_nanosleep function
The parameters of the function are:
| Parameter | Description |
| seconds | It specifies the number of seconds to delay the script. |
| nanoseconds | It specifies the number of nanoseconds to delay the script. |
Example
An example of the function is:
<?php
echo time_nanosleep(2,20000)? 'true':'false';
echo "</br>";
if(time_nanosleep(0,50000000)===true)
{
echo "Slept for a half of a second\n";
}
else
{
echo "Something went wrong!";
}
?>
Output
PHP time_sleep_until() Function
The PHP Miscellaneous time_sleep_until function puts the script asleep until the specified time and this function returns true on success or false on failure.
Syntax
| time_sleep_until(timestamp) |
Example
An example of the function is:
<?php
var_dump(time_sleep_until(time()+10));
?>
Output
PHP uniqid() Function
The PHP Miscellaneous uniqid function generates a unique id based on the micro time and this function returns the unique identifier, as a string.
Syntax
| uniqid(prefix,more_entropy) |
Parameter in uniqid function
The parameters of the function are:
| Parameter | Description |
| prefix | It specifies the prefix of the unique id. |
| more_entropy | It specifies more entropy at the end of the return value. |
Example
An example of the function is:
<?php
echo uniqid();
?>
Output
PHP unpack() Function
The PHP Miscellaneous unpack function unpacks data from a binary string and this function returns an associative array containing unpacked elements of the binary string.
Syntax
| unpack(format,data) |
Parameter in unpack function
The parameters of the function are:
| Parameter | Description |
| format | It specifies the format to use when unpacking data and its possible values are:
|
| data | It specifies the binary data to be unpacked. |
Example
An example of the function is:
<?php
echo "<pre>";
$content= "PHP";
print_r( unpack("C*",$content));
?>
Output
PHP usleep() Function
The PHP Miscellaneous usleep function delays execution in microseconds and this function returns no value.
Syntax
| unsleep(microseconds) |
Parameter in usleep function
The parameter of the function is:
| Parameter | Description |
| microseconds | It specifies the number of micro seconds to delay the script. |
Example
An example of the function is:
<?php
print_r(date('h:i:s'));
usleep(10000000);
echo "</br>";
print_r(date('h:i:s')); // it prints after 10 seconds time.
?>
Output

Comments
Join the conversation! Your thoughts help the community grow.