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.

3 Answers 3

4

This article will help you.

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

Sign up to request clarification or add additional context in comments.

1 Comment

Good article. I wanted to avoid the slow query log, but oh well.
2

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...
}

Comments

0

DebugKit is your friend. There should be versions suitable for Cake 1.3, 2.x and 3.x. It has a beautiful toolbar that displays all your SQL queries and the time taken to run each.

https://github.com/cakephp/debug_kit

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.