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?
Contents
- 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.
index.php
$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.";
example PHP code:
$sql_query = 'SELECT id, pname FROM products LIMIT 5'; $msc = microtime(true); mysql_query($sql_query); $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 infinityknow.com 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.
I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.