В одном из самых популярных языков PHP programming contains a rich library of functions. Each of them has its own properties, but because of the large number of operations and similar names, developers often get confused. Questions are caused by the PHP microtime function - what does it do and how does it differ from those similar to it?
Microtime function
In PHP microtime returns Unix time as the result,and up to microseconds. Despite the built-in operation in the programming language, it is not able to work on all systems. In earlier versions of operating systems where there is no system call gettimeofday (), this function will produce an incorrect result.
Syntax microtime () has only one argument- it determines in which data type the result can be returned. If the value corresponding to true (with the English word "true") is specified in brackets, then instead of numeric data the function returns the string. In the absence of any parameters (which is zero), the value will be false (with the English word "false"), the time will be returned in the format msec sec. Here, the first number will be the number of microseconds that have elapsed since the beginning of the current second, and the second is the total time elapsed since 1970, expressed in seconds.
To use in PHP microtime () it is necessaryif there is a need to find out how long it takes to execute a particular code segment. Most often, this mechanism is used to optimize the program.
Time difference
As a similar feature with microtime, PHP has a simpler time. Unlike its more accurate "sister", the result of using the function time () - the number of seconds that have passed since the beginning of the Unix era, that is, with January 1, 1970, 00:00:00 GMT. With the help of time () you can achieve the time difference between the two points of the program, however, with less accuracy.
If you want to get the system time, then you should use the date () function. If you need to obtain the maximum accuracy of the difference, it is best to choose the function PHP - microtime.