How to measure query execution time

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

How to measure query execution time

Post by matthijs »

How can I get back the query execution time in PHP? I know the command line automatically returns the query time. But I'd like to have the results in my php scripts.
marcth
Forum Contributor
Posts: 142
Joined: Mon Aug 25, 2008 8:16 am

Re: How to measure query execution time

Post by marcth »

Code: Select all

 
<?php
$time_start = microtime(true);
 
// Sleep for a while
usleep(100);
 
$time_end = microtime(true);
$time = $time_end - $time_start;
 
echo "Did nothing in $time seconds\n";
?>
Post Reply