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

We Are Recommending You

Laravel 10 Cron Job Task Scheduling Tutorial

Read Now →

Ubuntu PHP bz2 Extension Install Commands Example

Read Now →

How to Remove HTML Tags from String in Laravel?

Read Now →

How to Use Enum in Laravel?

Read Now →

PHP MySQL Column Sorting Example Tutorial

Read Now →

How to Make Read More Link from String in PHP?

Read Now →

How to Remove Duplicate Values from Array in PHP?

Read Now →

How to Get File Name without Extension in PHP?

Read Now →

How to Increase Upload File Size Limit PHP in Ubuntu?

Read Now →

How to Check If String is URL or Not in PHP?

Read Now →

How to Count Number of Files in a Directory in PHP?

Read Now →

How to Find Day Name from Specific Date in PHP?

Read Now →

How to Get Query Log in Laravel Eloquent?

Read Now →