I have a production CakePHP site where I ne开发者_运维知识库ed 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.
This article will help you.
If you have access to MySQL configuration file you can log slow queries by enabling log-slow-queries setting.
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...
}
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
精彩评论