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 explode

1.php Execution Time:$begin=Microtime(true);//gets the time that the program started executing//some code here to execute$stop=Microtime(true);//gets the time that the program execution endedList($m 0,$s 0)=Explode(" ",$begin);List($m 1,$s 1)=Explode(" ",$stop);$runtime=($s 1+$m 1-$s 0-$m 0) *1000;Echo' <br/> Current script execution time: '.$etime-$stime.‘ microseconds; 2.SQL Execution time (actually the same as above):$begin=Microtime();mysql_query($sql);$stop=Microtime();List($m 0,$s 0)=Explode(" ",$begin);List($m 1,$s 1)=Explode(" ",$stop);$runtime=round(($s 1+$m 1-$s 0-$m 0) *1000,4);Echo' <br/> Current script execution time: '.$runtime.‘ Ms ';

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 ()

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.