esedic
3/6/2015 - 10:27 AM

Joomla 2.5 Slow Query Logger Hack

Joomla 2.5 Slow Query Logger Hack

<?php
// We will hack file /libraries/joomla/database/database/mysqli.php
// Create a backup copy of the file

// Find this at row 381 inside public function execute()
$this->cursor = mysqli_query($this->connection, $sql);

// Change to:
$start = microtime(true);
$this->cursor = mysqli_query($this->connection, $sql);
$execution_time = round((microtime(true) - $start)*1000);
if( $execution_time > 200 ) {
    file_put_contents(dirname(__FILE__) . '../../../../../mysqli.slow_queries.log', "\r\n\r\n\r\nDatetime: " . date('Y-m-d H:i:s') . "\r\nExecution time: " . $execution_time . " milliseconds\r\n" . $sql, FILE_APPEND);
}

// The log file created is located in Joomla install root folder and is named mysqli.slow_queries.log
// The if statement checks if the query took longer than 200 milliseconds (0.2 seconds) to execute, 
// you will want to adjust this to fit your needs for speed. Or make it >= 0 if you want to log everything.

?>