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?