james Oduro james Oduro - 6 months ago 14
PHP Question

How to get the amount of time a query will take in php?

I am getting result from database and I want to print the amount of seconds or minute it took to bring me the result.

something like this:

if($fba_num_rows > 0){
//print the amount of time the query took
//like "Search completed in 0.57 seconds"

}


How do i do this? please help.

Answer

Use microtime function:

if($fba_num_rows > 0){
    $time_start = microtime(true);
    // your code

    $time_end = microtime(true);
    echo 'Search completed in ' . ($time_end - $time_start) . ' seconds';
}