Support for using optional parameters in microtime() was added in php 5.0.0. If taken without arguments, or with arguments that cannot be converted to true, or in earlier versions of PHP, microtime() returns the microsecond portion of the Unix time since the epoch, a space, and the number of seconds since the epoch. number. For example, the return value "0.41644100 1026683258" means that "1026683258.41644100 seconds" have elapsed since the epoch. A time value containing microseconds is useful for generating unique IDs. As long as a process does not generate more than one ID within a microsecond, it is guaranteed that a time value containing microseconds and the ID of the current process will form a unique ID value. Let’s look at another example: using microtime() (returned string format) to generate such an ID. Example 2: Use microtime() to generate an ID
Note: Example 2 is not very reliable in a multi-threaded system, because there is a non-trivial (but extremely small) probability that two threads of the same process will call microtime() within the same microsecond. |