Query time result in MySQL w/ PHP

☆樱花仙子☆ 提交于 2019-11-27 19:30:47
rayman86
$starttime = microtime(true);

//Do your query and stuff here

$endtime = microtime(true);
$duration = $endtime - $starttime; //calculates total time taken

This will give you the run time in microseconds.

this may be help you

http://dev.mysql.com/doc/refman/5.0/en/show-profile.html

mysql> SET profiling = 1;
Query OK, 0 rows affected (0.00 sec)

mysql> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> CREATE TABLE T1 (id INT);
Query OK, 0 rows affected (0.01 sec)

mysql> SHOW PROFILES;
+----------+----------+--------------------------+
| Query_ID | Duration | Query                    |
+----------+----------+--------------------------+
|        0 | 0.000088 | SET PROFILING = 1        |
|        1 | 0.000136 | DROP TABLE IF EXISTS t1  |
|        2 | 0.011947 | CREATE TABLE t1 (id INT) |
+----------+----------+--------------------------+

greetings

There are two possibilities I can tell you now:

  • wrap ->execute() with microtime() and measure it yourself, possibly wrapping whole "querying" code snippet within a class / function
  • run EXPLAIN query of that query and see if you can read some values from the returned data

Hope that helps.

If you are using MYSQL 5, you should better check SHOW PROFILE

http://dev.mysql.com/doc/refman/5.0/en/show-profile.html

and print the timings in php...or EXPLAIN the SQL statement which took longer or detail each query...by CPU etc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!