ComputersProgramming

What does the PHP microtime function do?

One of the most popular PHP programming languages contains a rich library of functions. Each of them differs in its properties, but because of the large number of operations and similar names, developers often have confusion. Questions are raised by the function of PHP microtime - what does it do and how does it differ from those similar to it?

Microtime function

In PHP, microtime returns the Unix time as a result, with an accuracy of microseconds. Despite the fact that the operation is embedded in the programming language, it does not work on all systems. In earlier versions of operating systems where there is no system call gettimeofday (), this function will produce an incorrect result.

The syntax of microtime () has only one argument - it determines in which data type it is possible to return the result. If the value corresponding to true is specified in parentheses, then the function returns a string instead of numeric data. If there are no parameters (which is zero), false will be specified, the time will be returned in msec sec format. Here, the first number will be the number of microseconds passed since the beginning of the current second, and the second is the total time since 1970, expressed in seconds.

Use in PHP microtime () is necessary in the event that there is a need to find out how long it takes to execute a particular piece of code. Most often this mechanism is used to optimize the program.

Time difference

As a similar function with microtime, PHP has a simpler - time. Unlike its more accurate "sister", the result of using the function time () is the number of seconds since the beginning of the Unix era, that is, from January 1, 1970, 00:00:00 GMT. Using time (), you can achieve a time difference between two points of the program, but with less accuracy.

If you want to get the system time, then you should use the date () function. If you need to get the maximum accuracy of the difference, it's best to choose the function PHP - microtime.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.birmiss.com. Theme powered by WordPress.