Posted by navaneeth_r on May 14, 2009 at 6:24am
How/where to check the number of queries running in a page other than devel module.
Regards
R.Navaneethakrishnan.
How/where to check the number of queries running in a page other than devel module.
Regards
R.Navaneethakrishnan.
Comments
You need to write a custom
You need to write a custom module for this. Drupal doesn't have a built-in way to do this.
First enable query logging:
<?phpvariable_set('dev_query',1);
?>
Then add code to display query info. A global variable called $queries will contain the time and SQL statements used. Here's an example:
<?php
// Database benchmarks
if(variable_get('dev_query',0)) {
global $queries;
$page_render = timer_read('page');
$time_query = 0;
foreach($queries as $q) {
$time_query += $q[1];
}
$time_query = round($time_query * 1000, 2); // Convert seconds to milliseconds
$percent_query = round(($time_query / $page_render) * 100);
$output = count($queries) . " queries @ {$time_query} ms ({$percent_query}%)";
}
?>
This will output something like "122 queries @ 165.49 ms (44%)." To be really accurate, use PHP's register_shutdown_function and dump it at the end of the page.
http://httpremix.com
Thanks for your response
Thanks for your response Mr.Jonah. How to do " PHP's register_shutdown_function and dump it at the end of the page"
In _db_query function in database.mysql.inc I am using following code to log the queries.
if($_SERVER['REMOTE_ADDR'] == '192.168.99.180') {
$file = '/var/www/html/example/files/query.txt';
$handle = fopen($file,'a+');
fwrite($handle,$query."\r\n");
fclose($handle);
}
Regards,
R.Navaneethakrishnan
I am trying to use the
I am trying to use the memcache.
I am logging the queries after and before enable memcache.
I am using following in _db_query function in database.mysql.inc I am using following code to log the queries.
if($_SERVER['REMOTE_ADDR'] == '192.168.99.180') {
$file = '/var/www/html/example/files/query.txt';
$handle = fopen($file,'a+');
fwrite($handle,$query."\r\n");
fclose($handle);
}
Before enable the memcache file size is 1.09 kb after enable the memcache the log file size is 11.09 kb.
In the memcache enable state I commented the following code then the queries are becoming 1.09 kb.
$conf = array(
'cache_inc' => './sites/all/modules/memcache/memcache.inc',
'memcache_servers' => array('localhost:11211' => 'default'),
'memcache_bins' => array('cache' => 'default','cache_views' => 'default', 'cache_page' => 'default', 'cache_path' => 'default','cache_filter' => 'default','cache_menu' => 'default'),
);
I have attached the log file before and after memcache. I need your support.
Regards
R.Navaneethakrishnan.