Improve developer habits by showing time cost of DB queries 12 years ago
I'm using multitail https://imgur.com/v4QVHUk
HN user
I'm using multitail https://imgur.com/v4QVHUk
I have the following on localhost at the bottom of every page:
<!--
head in <?php echo number_format($head_microttime, 4); ?> s
body in <?php echo number_format(microtime(true) - $starttime, 4); ?> s
<?php echo count($database->run_queries); ?> queries
<?php if (DEBUG) print_r($database->run_queries); ?>
-->Example output:
<!--
head in 0.3452 s
body in 0.7256 s
32 queries
Array(
[/Volumes/data/Sites/najnehnutelnosti/framework/initialize.php25] => SELECT name,value FROM settings
[/Volumes/data/Sites/najnehnutelnosti/framework/initialize.php45] => SELECT * FROM mod_captcha_control LIMIT 1
[/Volumes/data/Sites/najnehnutelnosti/framework/class.frontend.php123] => SELECT * FROM pages WHERE page_id = '1'
[/Volumes/data/Sites/najnehnutelnosti/framework/class.wb.php96] => SELECT publ_start,publ_end FROM sections WHERE page_id = '1'
[/Volumes/data/Sites/najnehnutelnosti/framework/frontend.functions.php28] => SELECT directory FROM addons WHERE type = 'module' AND function = 'snippet'
...etc
)
-->The array keys are the file from which the query originates with line number and the value is the query. I made it due duplicate queries. Query method in my class.database.php for the above output: public $run_queries = array();
function query($statement) {
$mysql = new mysql();
$mysql->query($statement);
$backtrace = debug_backtrace();
$this->run_queries[$backtrace[0]['file'].$backtrace[0]['line']] = $statement;
$this->set_error($mysql->error());
if($mysql->error()) {
return null;
} else {
return $mysql;
}
}