我正在从数据库中获取结果,我想打印得出结果所需的秒数或分钟数。
像这样的东西:
if($fba_num_rows > 0){
//print the amount of time the query took
//like "Search completed in 0.57 seconds"
}
我该怎么做?请帮忙。
使用microtime
函数:
if($fba_num_rows > 0){
$time_start = microtime(true);
// your code
$time_end = microtime(true);
echo 'Search completed in ' . ($time_end - $time_start) . ' seconds';
}
您可以始终使用PHP文档中所说的微时间函数。
类似:
$start_time = microtime(true);
// Do DB Ops
if($fba_num_rows > 0){
// Find the end time
$end_time = microtime(true);
// Calculate the time taken
$time_taken = $end_time - $start_time;
// Print the time
printf("Query took %f seconds", $time_taken);
}
希望它能有所帮助!