How do you check the efficiency of the PHP script execution (usually the script execution time) and the efficiency of the database SQL (usually the database query time) and locate and analyze the bottleneck of script execution and database query?

Source: Internet
Author: User
Tags php script

Php:

It is usually the beginning of the code you want to check to record a time, the end of the record a time. Take the difference value,

the efficiency of database SQL
SQL explain (MySQL), enable slow query log to record slow queries.
Usually also depends on the database design is reasonable, the demand is reasonable and so on.

But this time is generally very fast, in less than a second, so you can not directly use mktime ()function Getmicrotime () {

List ($usec, $sec) = Explode ("", Microtime ());

$num = ((float) $usec + (float) $sec);

Return sprintf ("%.4f", $num);

}

Usage:

$t _start = Getmicrotime ();

here, put the code you want to check.

$t _end = Getmicrotime ();

echo $t _end-$t _start;

The units of the output are seconds, and"%.4f" represents the exact four digits after the decimal point, which can be changed by itself

How do you check the efficiency of the PHP script execution (usually the script execution time) and the efficiency of the database SQL (usually the database query time) and locate and analyze the bottleneck of script execution and database query?

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.