ItSolutionStuff.com

How to Check Query Execution Time in PHP?

By Hardik Savani May 14, 2024
PHP

Hi Artisan,

This tutorial shows you how to check query execution time in php. If you have a question about php query execution time then I will give a simple example with a solution. This example will help you php get query execution time. This tutorial will give you a simple example of how to get query execution time in php.

If you are looking for how to get sql query execution time in php then i will give you simple example for it. we will use microtime() function to calculate query execution time in php.

so, let's see the simple example code:

index.php

<?php

$startTime = microtime(true);

$connection = new mysqli("localhost","root","root","laravel10_crud");

$result = mysqli_query($connection, "SELECT * FROM users");

$endTime = microtime(true);

$executionTime = $endTime - $startTime;

echo "Query took " . $executionTime . " seconds to execute.";

?>

Output:

Query took 0.0032229423522949 seconds to execute.

I hope it can help you...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube