views:

37

answers:

2

I have a production CakePHP site where I need to troubleshoot a slow SQL query. I want access to that great table CakePHP creates with the actual SQL query, execution time, etc, but I can't set the DEBUG level to 3 on a production site.

I imagine this is a simple but I just can't seem to figure out how I can get this information for a specific script and do something with it, like save it to a log file.

+4  A: 

This article will help you.

If you have access to MySQL configuration file you can log slow queries by enabling log-slow-queries setting.

bancer
Good article. I wanted to avoid the slow query log, but oh well.
Justin
+2  A: 

For Cake 1.3 (not sure if this works in 1.2), have a look at /cake/libs/view/elements/sql_dump.ctp and adapt it to your needs:

$sources = ConnectionManager::sourceList();

foreach ($sources as $source) {
    $db =& ConnectionManager::getDataSource($source);
    if (!$db->isInterfaceSupported('getLog')) {
        continue;
    }

    $log = $db->getLog();

    // examine $log...
}
deceze
Thanks, I'm on 1.2 right now but will eventually move.
Justin