Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to see current query response time in browser?

Is there any way to see current mysql query and its response time in browser? I am working on simple php not on any framework. Anybody know any addons for FF which gives me this information.

Please help

thanks

like image 559
user729022 Avatar asked Feb 02 '26 20:02

user729022


1 Answers

I use the profiling function of MySQL server (from 5.0.37).

<?php

// profiling init
$set_profiling = $mysqli->query( 'SET profiling = 1' );

// some stuff
$result1 = $mysqli->query( 'SELECT DESTINATIONCODE, ZONENAME FROM ZONES' );
$result2 = $mysqli->query( 'SELECT ZONENAME FROM ZONES' );


// showing profiling printout
$show_profiles = $mysqli->query( 'SHOW PROFILES' );
while( $row = $show_profiles->fetch_assoc() ) {
    echo '<pre>';   
    print_r( $row );    
    echo '</pre>'
}

In addition, if you want a more detailed report after each query you can use:

$show_profile = $mysqli->query( 'SHOW PROFILE' );

Check http://dev.mysql.com/tech-resources/articles/using-new-query-profiler.html .

That's a bit raw visualization but it works.

Example output:

Array
(
    [Query_ID] => 1
    [Duration] => 0.00012000
    [Query] => SELECT DESTINATIONCODE, ZONENAME FROM ZONES
)
Array
(
    [Query_ID] => 2
    [Duration] => 0.00006800
    [Query] => SELECT ZONENAME FROM ZONES
)

And detail for #1 query:

Array
(
    [Status] => (initialization)
    [Duration] => 0.000002
)
Array
(
    [Status] => checking query cache for query
    [Duration] => 0.000003
)
Array
(
    [Status] => checking privileges on cached 
    [Duration] => 0.000002
)
Array
(
    [Status] => checking permissions
    [Duration] => 0.000001
)
Array
(
    [Status] => sending cached result to clien
    [Duration] => 0.000056
)
Array
(
    [Status] => logging slow query
    [Duration] => 0.000001
)
like image 169
Fabio Mora Avatar answered Feb 04 '26 10:02

Fabio Mora



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!