PHP gets milliseconds of time microtime () Usage _php tutorial

Source: Internet
Author: User
In PHP if we want to get milliseconds to pass the Microtime () and then to convert, let me give you a few examples of friends, I hope that will be helpful to everyone.

The problem is not afraid of retarded ... Remember everything?

The code is as follows Copy Code

function Getmicrotime ()
{
List ($usec, $sec) = Explode ("", Microtime ());
return (float) $usec + (float) $sec);
}

is actually dealing with microtime () this function.

Microtime () The return value of this function is this form:

0.06261400 1303715872

The space is followed by the current timestamp, and the space is preceded by the current exact time

example, calculating the page execution time function

The code is as follows Copy Code

/**
* 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 secondsn";
?>

http://www.bkjia.com/PHPjc/633053.html www.bkjia.com true http://www.bkjia.com/PHPjc/633053.html techarticle in PHP If we want to get milliseconds to pass the Microtime () and then to convert, let me give you a few examples of friends, I hope that will be helpful to everyone. The problem is not afraid of retarded everything ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.