Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

microtime(3) [php man page]

MICROTIME(3)								 1							      MICROTIME(3)

microtime - Return current Unix timestamp with microseconds

SYNOPSIS
mixed microtime ([bool $get_as_float = false]) DESCRIPTION
microtime(3) returns the current Unix timestamp with microseconds. This function is only available on operating systems that support the gettimeofday() system call. PARAMETERS
o $get_as_float - If used and set to TRUE, microtime(3) will return a float instead of a string, as described in the return values section below. RETURN VALUES
By default, microtime(3) returns a string in the form "msec sec", where sec is the number of seconds since the Unix epoch (0:00:00 January 1,1970 GMT), and msec measures microseconds that have elapsed since sec and is also expressed in seconds. If $get_as_float is set to TRUE, then microtime(3) returns a float, which represents the current time in seconds since the Unix epoch accurate to the nearest microsecond. EXAMPLES
Example #1 Timing script execution with microtime(3) <?php /** * Simple function to replicate PHP 5 behaviour */ function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $time_start = microtime_float(); // Sleep for a while usleep(100); $time_end = microtime_float(); $time = $time_end - $time_start; echo "Did nothing in $time seconds "; ?> Example #2 Timing script execution in PHP 5 <?php $time_start = microtime(true); // Sleep for a while usleep(100); $time_end = microtime(true); $time = $time_end - $time_start; echo "Did nothing in $time seconds "; ?> Example #3 microtime(3) and REQUEST_TIME_FLOAT (as of PHP 5.4.0) <?php // Randomize sleeping time usleep(mt_rand(100, 10000)); // As of PHP 5.4.0, REQUEST_TIME_FLOAT is available in the $_SERVER superglobal array. // It contains the timestamp of the start of the request with microsecond precision. $time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]; echo "Did nothing in $time seconds "; ?> SEE ALSO
time(3). PHP Documentation Group MICROTIME(3)

Check Out this Related Man Page

UNIQID(3)								 1								 UNIQID(3)

uniqid - Generate a unique ID

SYNOPSIS
string uniqid ([string $prefix = ""], [bool $more_entropy = false]) DESCRIPTION
Gets a prefixed unique identifier based on the current time in microseconds. Warning This function does not create random nor unpredictable strings. This function must not be used for security purposes. Use a cryp- tographically secure random function/generator and cryptographically secure hash functions to create unpredictable secure IDs. PARAMETERS
o $prefix - Can be useful, for instance, if you generate identifiers simultaneously on several hosts that might happen to generate the iden- tifier at the same microsecond. With an empty $prefix, the returned string will be 13 characters long. If $more_entropy is TRUE, it will be 23 characters. o $more_entropy - If set to TRUE, uniqid(3) will add additional entropy (using the combined linear congruential generator) at the end of the return value, which increases the likelihood that the result will be unique. RETURN VALUES
Returns the unique identifier, as a string. EXAMPLES
Example #1 uniqid(3) Example <?php /* A uniqid, like: 4b3403665fea6 */ printf("uniqid(): %s ", uniqid()); /* We can also prefix the uniqid, this the same as * doing: * * $uniqid = $prefix . uniqid(); * $uniqid = uniqid($prefix); */ printf("uniqid('php_'): %s ", uniqid('php_')); /* We can also activate the more_entropy parameter, which is * required on some systems, like Cygwin. This makes uniqid() * produce a value like: 4b340550242239.64159797 */ printf("uniqid('', true): %s ", uniqid('', true)); ?> NOTES
Caution This function does not generate cryptographically secure tokens, in fact without being passed any additional parameters the return value is little different from microtime(3). If you need to generate cryptographically secure tokens use openssl_ran- dom_pseudo_bytes(3). Note Under Cygwin, the $more_entropy must be set to TRUE for this function to work. PHP Documentation Group UNIQID(3)
Man Page