0

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.

james Oduro
  • 673
  • 1
  • 6
  • 22

2 Answers2

0

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';
}
u_mulder
  • 54,101
  • 5
  • 48
  • 64
0

You can always use the microtime function as said in the PHP Docs.

Like:

$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);
}

Hope it helps!

Ikari
  • 3,176
  • 3
  • 29
  • 34