This contribution captures each query performed and stores it in an array which can easily be output for development purposes. Outputs page parse time, number of queries, and time for each query execution (debug mode).
In addition, it also adds COOKIE, SESSION, POST, and GET data to the output. This is handy for general script debugging.
This contribution adds the actual query performed to an array.
STEP 1 - Upload the included file
The file should be located in the upload directory of this contribution and is called "performance.php". This should be uploaded to your includes/ directory.STEP 2 - Edit includes/application_top.php
Find this code at the very top:define('PAGE_PARSE_START_TIME', microtime());
Directly AFTER add this:
$debug = array();
STEP 3 - Edit includes/functions/database.php
The difference between the two functions is that the $debug array is declared global so can be used throughout the script and the query is added to the array.Find this code (tep_db_query function):function tep_db_query($query, $link = 'db_link') {
REPLACE WITH THIS CODE:
global $$link;
if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
error_log('QUERY ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
}
$result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error());
if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
$result_error = mysql_error();
error_log('RESULT ' . $result . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
}
return $result;
}function tep_db_query($query, $link = 'db_link') {
global $$link, $debug;
$query_start = microtime();
if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
error_log('QUERY ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
}
$result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error());
if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
$result_error = mysql_error();
error_log('RESULT ' . $result . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
}
$_start = explode(' ', $query_start);
$_end = explode(' ', microtime());
$_time = number_format(($_end[1] + $_end[0] - ($_start[1] + $_start[0])), 6);
$debug['QUERIES'][] = $query;
$debug['TIME'][] = $_time;
return $result;
}STEP 4 - Edit includes/application_bottom.php
Find this code at the bottom of the file:if ( (GZIP_COMPRESSION == 'true') && ($ext_zlib_loaded == true) && ($ini_zlib_output_compression < 1) ) {
Above that code ADD this:
if ( (PHP_VERSION < '4.0.4') && (PHP_VERSION >= '4') ) {
tep_gzip_output(GZIP_LEVEL);
}
}include(DIR_WS_INCLUDES . 'performance.php');
STEP 5 - Enable "Display The Page Parse Times" option in the admin control panel
Find this code:Administration -> Configuration -> Logging -> Display The Page Parse Times = true
Now that the contribution is installed it will display the page parse time and the number of queries used to construct the page at the footer. To output the actual queries append the output request to any URL. For example, add ?output=1 to any URL and it will output the $debug array. It will enter the setting into session and output it on every page until you disable by appending ?output=0 to the URL. This allows you to see the $debug contents while regular customers only see the parse time and query count.
osCommerce is a community driven organization and as such the support base will fall entirely on the forum members. The base class is thoroughly commented and should be easy to follow for any coder. I offer limited support in-between paid projects (feeding my family comes first before volunteer time).
If you use this contribution and find it useful a small donation can be made via PayPal. This will enable me to offer one-on-one support and also fund releasing other contributions. In addition, if you make a donation it'll make you eligible for other performance optimization contributions that are not released!
This contribution is original work and nothing is borrowed. Enjoy!