Query time result in MySQL w/ PHP

前端 未结 4 574
独厮守ぢ
独厮守ぢ 2020-12-05 03:07

Is there a way that I can get the time of a MySQL query (specifically with PHP)? The actual time it took to complete the query, that is.

Something such as: Results 1

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 03:55

    $starttime = microtime(true);
    
    //Do your query and stuff here
    
    $endtime = microtime(true);
    $duration = $endtime - $starttime; //calculates total time taken
    

    NOTE that this will give you the run time in seconds(not microseconds) to the nearest microsecond due to get_as_float parameter being true. See this

提交回复
热议问题