I have a shared hosting where I have my website and MySQL database. I've installed a open source script for statistics (phpMyVisites) and it started to work very slow lately. It's written using some kind of framework and has many PHP files. I know that to find slow queries I can use slow query log functionality in MySQL. But on this shared hosting I can not use this method because I can not change my.cnf. I don't want to change my statistics script to other and I don't want to mess around with all files of this script to find out where to put diagnostics code to log queries manually. I would like to do it without changes in PHP code.
So my question is:
How to log slow queries in these coditions?:
Is there any method to do this in simple, easy, fast way?
Hmm, perhaps make a function that checks how long a sql query took before it returned a value? Then if it was over a specified amount log it... eg in php i'd do it like this
$before = time();
//run your query
$after = time();
$difference = $after - $before
if($difference > 5000)
//Log query
That emulates the slog query logger, i dont think theres a way of enabling it on shared hosting.
Hope this helps :)
I took a quick look at phpMyVisites. In config.inc.php I found the following:
// Other
if(!defined('DEBUG')) define('DEBUG', false);
define('DEFAULT_ACTION', false);
error_reporting( E_ALL );
if(DEBUG)
{
define('PRINT_TIME', false);
define('PRINT_QUERY_COUNT', true);
define('SAVE_DB_LOG', true);
define('PRINT_QUERY', true);
}
I suspect SAVE_DB_LOG might be a good starting point, so I would try to turn DEBUG mode on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With