How to get the execution time of a MySQL query from PHP?

Today, We want to share with you check query execution time php.In this post we will show you php check time taken to execute script, hear for php get query execution time we will give you demo and example for implement.In this post, we will learn about PHP sleep delay Function increasing execution time with an example.

how to calculate query execution time in mysql?

  • MySQL Query the start time before the query is executed.
  • Execute your SQL query.
  • Query the end time after the query has finished running.
  • Calculate the difference in microseconds.
  • Format the time so that it only shows 10 decimal places.
  • Print out the seconds it took for the query to execute or run.
Also Read This πŸ‘‰   registration and signin form in php and mysql with validation


$started = microtime(true);

mysql_query("SELECT id, pname FROM products LIMIT 5");

$end = microtime(true);

$total_diff = $end - $started;

$getqueryTime = number_format($total_diff, 10);

echo "Here Simple SQL query took $getqueryTime seconds.";

Free Live Chat for Any Issue

example PHP code:

$sql_query = 'SELECT id, pname FROM products LIMIT 5';
$msc = microtime(true);
$total_diff = microtime(true)-$msc;
echo $total_diff . ' s'; // in seconds
echo ($total_diff * 1000) . ' ms'; // in millseconds

I hope you get an idea about php calculate execution time.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.