예제 #1
0
function testdb($db)
{
    if (!$db) {
        return;
    }
    echo "<font size=1>";
    print_r($db->ServerInfo());
    echo " user="******"</font>";
    $perf = NewPerfMonitor($db);
    # unit tests
    if (0) {
        //$DB->debug=1;
        echo "Data Cache Size=" . $perf->DBParameter('data cache size') . '<p>';
        echo $perf->HealthCheck();
        echo $perf->SuspiciousSQL();
        echo $perf->ExpensiveSQL();
        echo $perf->InvalidSQL();
        echo $perf->Tables();
        echo "<pre>";
        echo $perf->HealthCheckCLI();
        $perf->Poll(3);
        die;
    }
    if ($perf) {
        $perf->UI(3);
    }
}
예제 #2
0
function &adodb_log_sql(&$conn, $sql, $inputarr)
{
    /**
     OXID changes - create separate mysql connection for logging for not loosing info from last query (R)
    */
    $_logSqlDbInstance = $conn->_logSqlDbInstance;
    $perf_table = adodb_perf::table();
    $conn->_logsql = false;
    // replaces setting ::fnExecute=false in ADOdb
    $t0 = microtime();
    $rs =& $conn->Execute($sql, $inputarr);
    $t1 = microtime();
    $conn->_logsql = true;
    // reverse setting ::_logsql=false
    if (!$_logSqlDbInstance) {
        $myConfig = oxConfig::getInstance();
        $conn->_logSqlDbInstance = $_logSqlDbInstance =& NewADOConnection($myConfig->getConfigParam("dbType"));
        $_logSqlDbInstance->_connect($conn->host, $conn->username, $conn->password, $conn->database, false, true);
    }
    if (!empty($conn->_logsql)) {
        //$conn->_logsql = false; // disable logsql error simulation
        $dbT = $conn->dbtype;
        $a0 = explode(' ', $t0);
        $a0 = (double) $a0[1] + (double) $a0[0];
        $a1 = explode(' ', $t1);
        $a1 = (double) $a1[1] + (double) $a1[0];
        $time = $a1 - $a0;
        if (!$rs) {
            $errM = $conn->ErrorMsg();
            $errN = $conn->ErrorNo();
            $tracer = substr('ERROR: ' . htmlspecialchars($errM), 0, 250);
        } else {
            $tracer = '';
            $errM = '';
            $errN = 0;
        }
        if (isset($_SERVER['HTTP_HOST'])) {
            $tracer .= '<br>' . $_SERVER['HTTP_HOST'];
            if (isset($_SERVER['PHP_SELF'])) {
                $tracer .= $_SERVER['PHP_SELF'];
            }
        } elseif (isset($_SERVER['PHP_SELF'])) {
            $tracer .= '<br>' . $_SERVER['PHP_SELF'];
        }
        // OXID - added backtrace
        $_aTrace = debug_backtrace();
        $_sTrace = '';
        foreach ($_aTrace as $_trace) {
            $_sTrace .= "{$_trace['file']} - {$_trace['function']}:{$_trace['line']}\n";
        }
        $tracer .= "\n\nBacktrace:\n" . $_sTrace;
        $tracer = (string) substr($tracer, 0, 5000);
        if (is_array($inputarr)) {
            if (is_array(reset($inputarr))) {
                $params = 'Array sizeof=' . sizeof($inputarr);
            } else {
                // Quote string parameters so we can see them in the
                // performance stats. This helps spot disabled indexes.
                $xar_params = $inputarr;
                foreach ($xar_params as $xar_param_key => $xar_param) {
                    if (gettype($xar_param) == 'string') {
                        $xar_params[$xar_param_key] = '"' . $xar_param . '"';
                    }
                }
                $params = implode(', ', $xar_params);
                if (strlen($params) >= 3000) {
                    $params = substr($params, 0, 3000);
                }
            }
        } else {
            $params = '';
        }
        if (is_array($sql)) {
            $sql = $sql[0];
        }
        $arr = array('b' => strlen($sql) . '.' . crc32($sql), 'c' => substr($sql, 0, 3900), 'd' => $params, 'e' => $tracer, 'f' => adodb_round($time, 6));
        //$saved = $_logSqlDbInstance->debug;
        //$_logSqlDbInstance->debug = 0;
        $d = $conn->sysTimeStamp;
        if (empty($d)) {
            $d = date("'Y-m-d H:i:s'");
        }
        /*
        // OCI/Informix/ODBC_MSSQL - not sure if/how available in adodb-lite so I've commented out the section for now - (Pádraic)
        */
        /*if ($dbT == 'oci8' && $dbT != 'oci8po')
                {
                    $isql = "insert into $perf_table values($d,:b,:c,:d,:e,:f)";
                }
                elseif($dbT == 'odbc_mssql' || $dbT == 'informix')
                {
                    $timer = $arr['f'];
                    if ($dbT == 'informix') $sql2 = substr($sql2,0,230);
        
                    $sql1 = $conn->qstr($arr['b']);
                    $sql2 = $conn->qstr($arr['c']);
                    $params = $conn->qstr($arr['d']);
                    $tracer = $conn->qstr($arr['e']);
        
                    $isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values($d,$sql1,$sql2,$params,$tracer,$timer)";
                    if ($dbT == 'informix') $isql = str_replace(chr(10),' ',$isql);
                    $arr = false;
                } else {*/
        $isql = "insert into {$perf_table} (created,sql0,sql1,params,tracer,timer) values( {$d},?,?,?,?,?)";
        //}
        // OXID change - added try catch wrapping
        try {
            $ok = $_logSqlDbInstance->Execute($isql, $arr);
        } catch (Exception $e) {
            $ok = false;
        }
        //$_logSqlDbInstance->debug = $saved;
        if ($ok) {
            //$_logSqlDbInstance->_logsql = true;
        } else {
            $err2 = $_logSqlDbInstance->ErrorMsg();
            //$_logSqlDbInstance->_logsql = true; // enable logsql error simulation
            $perf =& NewPerfMonitor($_logSqlDbInstance);
            if ($perf) {
                if ($perf->CreateLogTable()) {
                    $ok = $_logSqlDbInstance->Execute($isql, $arr);
                }
            } else {
                $ok = $_logSqlDbInstance->Execute("create table {$perf_table} (\r\n                created varchar(50),\r\n                sql0 varchar(250),\r\n                sql1 varchar(4000),\r\n                params varchar(3000),\r\n                tracer varchar(5000),\r\n                timer decimal(16,6))");
            }
            /*if (!$ok) {
                  ADOConnection::outp( "<p><b>LOGSQL Insert Failed</b>: $isql<br>$err2</p>");
                  $conn->_logsql = false;
              }*/
        }
        //$conn->_errorMsg = $errM;
        //$conn->_errorCode = $errN;
    }
    return $rs;
}
예제 #3
0
function &adodb_log_sql(&$connx, $sql, $inputarr)
{
    $perf_table = adodb_perf::table();
    $connx->fnExecute = false;
    $t0 = microtime();
    $rs =& $connx->Execute($sql, $inputarr);
    $t1 = microtime();
    if (!empty($connx->_logsql) && (empty($connx->_logsqlErrors) || !$rs)) {
        global $ADODB_LOG_CONN;
        if (!empty($ADODB_LOG_CONN)) {
            $conn =& $ADODB_LOG_CONN;
            if ($conn->databaseType != $connx->databaseType) {
                $prefix = '/*dbx=' . $connx->databaseType . '*/ ';
            } else {
                $prefix = '';
            }
        } else {
            $conn =& $connx;
            $prefix = '';
        }
        $conn->_logsql = false;
        // disable logsql error simulation
        $dbT = $conn->databaseType;
        $a0 = explode(' ', $t0);
        $a0 = (double) $a0[1] + (double) $a0[0];
        $a1 = explode(' ', $t1);
        $a1 = (double) $a1[1] + (double) $a1[0];
        $time = $a1 - $a0;
        if (!$rs) {
            $errM = $connx->ErrorMsg();
            $errN = $connx->ErrorNo();
            $conn->lastInsID = 0;
            $tracer = substr('ERROR: ' . htmlspecialchars($errM), 0, 250);
        } else {
            $tracer = '';
            $errM = '';
            $errN = 0;
            $dbg = $conn->debug;
            $conn->debug = false;
            if (!is_object($rs) || $rs->dataProvider == 'empty') {
                $conn->_affected = $conn->affected_rows(true);
            }
            $conn->lastInsID = @$conn->Insert_ID();
            $conn->debug = $dbg;
        }
        if (isset($_SERVER['HTTP_HOST'])) {
            $tracer .= '<br>' . $_SERVER['HTTP_HOST'];
            if (isset($_SERVER['PHP_SELF'])) {
                $tracer .= htmlspecialchars($_SERVER['PHP_SELF']);
            }
        } else {
            if (isset($_SERVER['PHP_SELF'])) {
                $tracer .= '<br>' . htmlspecialchars($_SERVER['PHP_SELF']);
            }
        }
        //$tracer .= (string) adodb_backtrace(false);
        $tracer = (string) substr($tracer, 0, 500);
        if (is_array($inputarr)) {
            if (is_array(reset($inputarr))) {
                $params = 'Array sizeof=' . sizeof($inputarr);
            } else {
                // Quote string parameters so we can see them in the
                // performance stats. This helps spot disabled indexes.
                $xar_params = $inputarr;
                foreach ($xar_params as $xar_param_key => $xar_param) {
                    if (gettype($xar_param) == 'string') {
                        $xar_params[$xar_param_key] = '"' . $xar_param . '"';
                    }
                }
                $params = implode(', ', $xar_params);
                if (strlen($params) >= 3000) {
                    $params = substr($params, 0, 3000);
                }
            }
        } else {
            $params = '';
        }
        if (is_array($sql)) {
            $sql = $sql[0];
        }
        if ($prefix) {
            $sql = $prefix . $sql;
        }
        $arr = array('b' => strlen($sql) . '.' . crc32($sql), 'c' => substr($sql, 0, 3900), 'd' => $params, 'e' => $tracer, 'f' => adodb_round($time, 6));
        //var_dump($arr);
        $saved = $conn->debug;
        $conn->debug = 0;
        $d = $conn->sysTimeStamp;
        if (empty($d)) {
            $d = date("'Y-m-d H:i:s'");
        }
        if ($conn->dataProvider == 'oci8' && $dbT != 'oci8po') {
            $isql = "insert into {$perf_table} values({$d},:b,:c,:d,:e,:f)";
        } else {
            if ($dbT == 'odbc_mssql' || $dbT == 'informix' || strncmp($dbT, 'odbtp', 4) == 0) {
                $timer = $arr['f'];
                if ($dbT == 'informix') {
                    $sql2 = substr($sql2, 0, 230);
                }
                $sql1 = $conn->qstr($arr['b']);
                $sql2 = $conn->qstr($arr['c']);
                $params = $conn->qstr($arr['d']);
                $tracer = $conn->qstr($arr['e']);
                $isql = "insert into {$perf_table} (created,sql0,sql1,params,tracer,timer) values({$d},{$sql1},{$sql2},{$params},{$tracer},{$timer})";
                if ($dbT == 'informix') {
                    $isql = str_replace(chr(10), ' ', $isql);
                }
                $arr = false;
            } else {
                if ($dbT == 'db2') {
                    $arr['f'] = (double) $arr['f'];
                }
                $isql = "insert into {$perf_table} (created,sql0,sql1,params,tracer,timer) values( {$d},?,?,?,?,?)";
            }
        }
        global $ADODB_PERF_MIN;
        if ($errN != 0 || $time >= $ADODB_PERF_MIN) {
            $ok = $conn->Execute($isql, $arr);
        } else {
            $ok = true;
        }
        $conn->debug = $saved;
        if ($ok) {
            $conn->_logsql = true;
        } else {
            $err2 = $conn->ErrorMsg();
            $conn->_logsql = true;
            // enable logsql error simulation
            $perf =& NewPerfMonitor($conn);
            if ($perf) {
                if ($perf->CreateLogTable()) {
                    $ok = $conn->Execute($isql, $arr);
                }
            } else {
                $ok = $conn->Execute("create table {$perf_table} (\n\t\t\t\tcreated varchar(50),\n\t\t\t\tsql0 varchar(250), \n\t\t\t\tsql1 varchar(4000),\n\t\t\t\tparams varchar(3000),\n\t\t\t\ttracer varchar(500),\n\t\t\t\ttimer decimal(16,6))");
            }
            if (!$ok) {
                ADOConnection::outp("<p><b>LOGSQL Insert Failed</b>: {$isql}<br>{$err2}</p>");
                $conn->_logsql = false;
            }
        }
        $connx->_errorMsg = $errM;
        $connx->_errorCode = $errN;
    }
    $connx->fnExecute = 'adodb_log_sql';
    return $rs;
}
예제 #4
0
 /**
  * db debug info formatter (collects adodb logs)
  *
  * @return string
  */
 public function formatAdoDbPerf()
 {
     $oPerfMonitor = @NewPerfMonitor(oxDb::getDb());
     if ($oPerfMonitor) {
         ob_start();
         $oPerfMonitor->UI(5);
         return ob_get_clean();
     }
     return '';
 }
예제 #5
0
function &adodb_log_sql(&$conn, $sql, $inputarr)
{
    global $HTTP_SERVER_VARS;
    $perf_table = adodb_perf::table();
    $conn->fnExecute = false;
    $t0 = microtime();
    $rs =& $conn->Execute($sql, $inputarr);
    $t1 = microtime();
    if (!empty($conn->_logsql)) {
        $conn->_logsql = false;
        // disable logsql error simulation
        $dbT = $conn->databaseType;
        $a0 = split(' ', $t0);
        $a0 = (double) $a0[1] + (double) $a0[0];
        $a1 = split(' ', $t1);
        $a1 = (double) $a1[1] + (double) $a1[0];
        $time = $a1 - $a0;
        if (!$rs) {
            $errM = $conn->ErrorMsg();
            $errN = $conn->ErrorNo();
            $conn->lastInsID = 0;
            $tracer = substr('ERROR: ' . htmlspecialchars($errM), 0, 250);
        } else {
            $tracer = '';
            $errM = '';
            $errN = 0;
            $dbg = $conn->debug;
            $conn->debug = false;
            if (!is_object($rs) || $rs->dataProvider == 'empty') {
                $conn->_affected = $conn->affected_rows(true);
            }
            $conn->lastInsID = @$conn->Insert_ID();
            $conn->debug = $dbg;
        }
        if (isset($HTTP_SERVER_VARS['HTTP_HOST'])) {
            $tracer .= '<br>' . $HTTP_SERVER_VARS['HTTP_HOST'];
            if (isset($HTTP_SERVER_VARS['PHP_SELF'])) {
                $tracer .= $HTTP_SERVER_VARS['PHP_SELF'];
            }
        } else {
            if (isset($HTTP_SERVER_VARS['PHP_SELF'])) {
                $tracer .= '<br>' . $HTTP_SERVER_VARS['PHP_SELF'];
            }
        }
        //$tracer .= (string) adodb_backtrace(false);
        $tracer = (string) substr($tracer, 0, 500);
        if (is_array($inputarr)) {
            if (is_array(reset($inputarr))) {
                $params = 'Array sizeof=' . sizeof($inputarr);
            } else {
                $params = '';
                $params = implode(', ', $inputarr);
                if (strlen($params) >= 3000) {
                    $params = substr($params, 0, 3000);
                }
            }
        } else {
            $params = '';
        }
        if (is_array($sql)) {
            $sql = $sql[0];
        }
        $arr = array('b' => trim(substr($sql, 0, 230)), 'c' => substr($sql, 0, 3900), 'd' => $params, 'e' => $tracer, 'f' => adodb_round($time, 6));
        //var_dump($arr);
        $saved = $conn->debug;
        $conn->debug = 0;
        $d = $conn->sysTimeStamp;
        if (empty($d)) {
            $d = date("'Y-m-d H:i:s'");
        }
        if ($conn->dataProvider == 'oci8' && $dbT != 'oci8po') {
            $isql = "insert into {$perf_table} values({$d},:b,:c,:d,:e,:f)";
        } else {
            if ($dbT == 'odbc_mssql' || $dbT == 'informix') {
                $timer = $arr['f'];
                if ($dbT == 'informix') {
                    $sql2 = substr($sql2, 0, 230);
                }
                $sql1 = $conn->qstr($arr['b']);
                $sql2 = $conn->qstr($arr['c']);
                $params = $conn->qstr($arr['d']);
                $tracer = $conn->qstr($arr['e']);
                $isql = "insert into {$perf_table} (created,sql0,sql1,params,tracer,timer) values({$d},{$sql1},{$sql2},{$params},{$tracer},{$timer})";
                if ($dbT == 'informix') {
                    $isql = str_replace(chr(10), ' ', $isql);
                }
                $arr = false;
            } else {
                $isql = "insert into {$perf_table} (created,sql0,sql1,params,tracer,timer) values( {$d},?,?,?,?,?)";
            }
        }
        $ok = $conn->Execute($isql, $arr);
        $conn->debug = $saved;
        if ($ok) {
            $conn->_logsql = true;
        } else {
            $err2 = $conn->ErrorMsg();
            $conn->_logsql = true;
            // enable logsql error simulation
            $perf =& NewPerfMonitor($conn);
            if ($perf) {
                if ($perf->CreateLogTable()) {
                    $ok = $conn->Execute($isql, $arr);
                }
            } else {
                $ok = $conn->Execute("create table {$perf_table} (\n\t\t\t\tcreated varchar(50),\n\t\t\t\tsql0 varchar(250),\n\t\t\t\tsql1 varchar(4000),\n\t\t\t\tparams varchar(3000),\n\t\t\t\ttracer varchar(500),\n\t\t\t\ttimer decimal(16,6))");
            }
            if (!$ok) {
                ADOConnection::outp("<p><b>LOGSQL Insert Failed</b>: {$isql}<br>{$err2}</p>");
                $conn->_logsql = false;
            }
        }
        $conn->_errorMsg = $errM;
        $conn->_errorCode = $errN;
    }
    $conn->fnExecute = 'adodb_log_sql';
    return $rs;
}
예제 #6
0
function &adodb_log_sql(&$conn, $sql, $inputarr)
{
    /**
     OXID changes - create separate mysql connection for logging for not loosing info from last query (R)
    */
    if (isset($_SESSION['debugPHP']) && is_string($_SESSION['debugPHP'])) {
        $sIdent = $_SESSION['debugPHP'];
    } else {
        $sIdent = false;
    }
    $_logSqlDbInstance = $conn->_logSqlDbInstance;
    $perf_table = 'adodb_debugphp_logsql';
    $conn->_logsql = false;
    // replaces setting ::fnExecute=false in ADOdb
    $t0 = microtime();
    $rs =& $conn->Execute($sql, $inputarr);
    $t1 = microtime();
    $conn->_logsql = true;
    // reverse setting ::_logsql=false
    if (!$_logSqlDbInstance) {
        $myConfig = oxConfig::getInstance();
        $conn->_logSqlDbInstance = $_logSqlDbInstance =& NewADOConnection($myConfig->getConfigParam("dbType"));
        $_logSqlDbInstance->_connect($conn->host, $conn->username, $conn->password, $conn->database, false, true);
    }
    if (!empty($conn->_logsql) && $sIdent != false && strpos(strtolower(trim($sql)), 'select') !== true && strpos(strtolower(trim($sql)), 'show') !== true) {
        //if (!empty($conn->_logsql)) {
        //$conn->_logsql = false; // disable logsql error simulation
        $dbT = $conn->dbtype;
        $a0 = explode(' ', $t0);
        $a0 = (double) $a0[1] + (double) $a0[0];
        $a1 = explode(' ', $t1);
        $a1 = (double) $a1[1] + (double) $a1[0];
        $time = $a1 - $a0;
        if (!$rs) {
            $errM = $conn->ErrorMsg();
            $errN = $conn->ErrorNo();
            $tracer = substr('ERROR: ' . htmlspecialchars($errM), 0, 250);
        } else {
            $tracer = '';
            $errM = '';
            $errN = 0;
        }
        if (isset($_SERVER['HTTP_HOST'])) {
            $tracer .= $_SERVER['HTTP_HOST'];
            if (isset($_SERVER['PHP_SELF'])) {
                $tracer .= $_SERVER['PHP_SELF'];
            }
        } elseif (isset($_SERVER['PHP_SELF'])) {
            $tracer .= $_SERVER['PHP_SELF'];
        }
        if (strpos($tracer, "debugax/www/index.php") !== false) {
            return $rs;
        }
        $tracer = (string) substr($tracer, 0, 5000);
        if (is_array($inputarr)) {
            if (is_array(reset($inputarr))) {
                $params = 'Array sizeof=' . sizeof($inputarr);
            } else {
                // Quote string parameters so we can see them in the
                // performance stats. This helps spot disabled indexes.
                $xar_params = $inputarr;
                foreach ($xar_params as $xar_param_key => $xar_param) {
                    if (gettype($xar_param) == 'string') {
                        $xar_params[$xar_param_key] = '"' . $xar_param . '"';
                    }
                }
                $params = implode(', ', $xar_params);
                if (strlen($params) >= 3000) {
                    $params = substr($params, 0, 3000);
                }
            }
        } else {
            $params = '';
        }
        if (is_array($sql)) {
            $sql = $sql[0];
        }
        $arr = array('b' => strlen($sql) . '.' . crc32($sql), 'c' => substr($sql, 0, 3900), 'd' => json_encode($rs->fields), 'e' => $tracer, 'f' => adodb_round($time, 6));
        $d = $conn->sysTimeStamp;
        if (empty($d)) {
            $d = date("'Y-m-d H:i:s'");
        }
        $isql = "insert into {$perf_table} (created,sql0,sql1,params,tracer,timer,type, ident) values( {$d},?,?,?,?,?,'sql','{$sIdent}')";
        try {
            $ok = $_logSqlDbInstance->Execute($isql, $arr);
        } catch (Exception $e) {
            $ok = false;
        }
        if ($ok) {
        } else {
            $err2 = $_logSqlDbInstance->ErrorMsg();
            $perf =& NewPerfMonitor($_logSqlDbInstance);
            if ($perf) {
                if ($perf->CreateLogTable()) {
                    $ok = $_logSqlDbInstance->Execute($isql, $arr);
                }
            } else {
                $ok = $_logSqlDbInstance->Execute("CREATE TABLE IF NOT EXISTS `adodb_debugphp_logsql` (\r\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\r\n                  `created` datetime NOT NULL,\r\n                  `sql0` varchar(250) COLLATE latin1_general_ci NOT NULL,\r\n                  `sql1` text COLLATE latin1_general_ci NOT NULL,\r\n                  `params` text COLLATE latin1_general_ci NOT NULL,\r\n                  `tracer` text COLLATE latin1_general_ci NOT NULL,\r\n                  `timer` decimal(16,6) NOT NULL,\r\n                  `type` char(50) COLLATE latin1_general_ci NOT NULL,\r\n                  `ident` char(50) COLLATE latin1_general_ci NOT NULL,\r\n                  PRIMARY KEY (`id`),\r\n                  KEY `created` (`created`),\r\n                  KEY `ident` (`ident`)\r\n                ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;");
            }
        }
    }
    return $rs;
}
function &adodb_log_sql(&$conn, $sql, $inputarr)
{
    $perf_table = adodb_perf::table();
    $conn->_logsql = false;
    // replaces setting ::fnExecute=false in ADOdb
    $t0 = microtime();
    $rs =& $conn->Execute($sql, $inputarr);
    $t1 = microtime();
    $conn->_logsql = true;
    // reverse setting ::_logsql=false
    if (!empty($conn->_logsql)) {
        $conn->_logsql = false;
        // disable logsql error simulation
        $dbT = $conn->dbtype;
        $a0 = split(' ', $t0);
        $a0 = (double) $a0[1] + (double) $a0[0];
        $a1 = split(' ', $t1);
        $a1 = (double) $a1[1] + (double) $a1[0];
        $time = $a1 - $a0;
        if (!$rs) {
            $errM = $conn->ErrorMsg();
            $errN = $conn->ErrorNo();
            $tracer = substr('ERROR: ' . htmlspecialchars($errM), 0, 250);
        } else {
            $tracer = '';
            $errM = '';
            $errN = 0;
        }
        if (isset($_SERVER['HTTP_HOST'])) {
            $tracer .= '<br>' . $_SERVER['HTTP_HOST'];
            if (isset($_SERVER['PHP_SELF'])) {
                $tracer .= $_SERVER['PHP_SELF'];
            }
        } elseif (isset($_SERVER['PHP_SELF'])) {
            $tracer .= '<br>' . $_SERVER['PHP_SELF'];
        }
        $tracer = (string) substr($tracer, 0, 500);
        if (is_array($inputarr)) {
            if (is_array(reset($inputarr))) {
                $params = 'Array sizeof=' . sizeof($inputarr);
            } else {
                // Quote string parameters so we can see them in the
                // performance stats. This helps spot disabled indexes.
                $xar_params = $inputarr;
                foreach ($xar_params as $xar_param_key => $xar_param) {
                    if (gettype($xar_param) == 'string') {
                        $xar_params[$xar_param_key] = '"' . $xar_param . '"';
                    }
                }
                $params = implode(', ', $xar_params);
                if (strlen($params) >= 3000) {
                    $params = substr($params, 0, 3000);
                }
            }
        } else {
            $params = '';
        }
        if (is_array($sql)) {
            $sql = $sql[0];
        }
        $arr = array('b' => strlen($sql) . '.' . crc32($sql), 'c' => substr($sql, 0, 3900), 'd' => $params, 'e' => $tracer, 'f' => adodb_round($time, 6));
        $saved = $conn->debug;
        $conn->debug = 0;
        $d = $conn->sysTimeStamp;
        if (empty($d)) {
            $d = date("'Y-m-d H:i:s'");
        }
        /*
        // OCI/Informix/ODBC_MSSQL - not sure if/how available in adodb-lite so I've commented out the section for now - (Pádraic)
        */
        /*if ($dbT == 'oci8' && $dbT != 'oci8po')
        		{
        			$isql = "insert into $perf_table values($d,:b,:c,:d,:e,:f)";
        		}
        		elseif($dbT == 'odbc_mssql' || $dbT == 'informix')
        		{
        			$timer = $arr['f'];
        			if ($dbT == 'informix') $sql2 = substr($sql2,0,230);
        
        			$sql1 = $conn->qstr($arr['b']);
        			$sql2 = $conn->qstr($arr['c']);
        			$params = $conn->qstr($arr['d']);
        			$tracer = $conn->qstr($arr['e']);
        			
        			$isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values($d,$sql1,$sql2,$params,$tracer,$timer)";
        			if ($dbT == 'informix') $isql = str_replace(chr(10),' ',$isql);
        			$arr = false;
        		} else {*/
        $isql = "insert into {$perf_table} (created,sql0,sql1,params,tracer,timer) values( {$d},?,?,?,?,?)";
        //}
        $ok = $conn->Execute($isql, $arr);
        $conn->debug = $saved;
        if ($ok) {
            $conn->_logsql = true;
        } else {
            $err2 = $conn->ErrorMsg();
            $conn->_logsql = true;
            // enable logsql error simulation
            $perf =& NewPerfMonitor($conn);
            if ($perf) {
                if ($perf->CreateLogTable()) {
                    $ok = $conn->Execute($isql, $arr);
                }
            } else {
                $ok = $conn->Execute("create table {$perf_table} (\n\t\t\t\tcreated varchar(50),\n\t\t\t\tsql0 varchar(250), \n\t\t\t\tsql1 varchar(4000),\n\t\t\t\tparams varchar(3000),\n\t\t\t\ttracer varchar(500),\n\t\t\t\ttimer decimal(16,6))");
            }
            /*if (!$ok) {
            			ADOConnection::outp( "<p><b>LOGSQL Insert Failed</b>: $isql<br>$err2</p>");
            			$conn->_logsql = false;
            		}*/
        }
        $conn->_errorMsg = $errM;
        $conn->_errorCode = $errN;
    }
    return $rs;
}
예제 #8
0
<?php

include_once 'class/database/adodb/adodb.inc.php';
include_once 'config/config.properties.php';
session_start();
# session variables required for monitoring
$conn = ADONewConnection("mysql");
$conn->Connect($config["db_host"], $config["db_username"], $config["db_password"], $config["db_database"]);
$perf =& NewPerfMonitor($conn);
$perf->UI($pollsecs = 3600);
예제 #9
0
   Copyright (c) 2003 osCommerce
   ----------------------------------------------------------------------
   Released under the GNU General Public License
   --------------------------------------------------------------------- */
/** ensure this file is being included by a parent file */
defined('OOS_VALID_MOD') or die('Direct Access to this location is not allowed.');
if ($oEvent->installed_plugin('debug')) {
    echo '<pre>';
    print_r($_SESSION);
    echo '<br />';
    print_r($_GET);
    echo '<br />';
    print_r($_POST);
    echo '</pre>';
}
// shopping_cart
if (isset($_SESSION['new_products_id_in_cart'])) {
    unset($_SESSION['new_products_id_in_cart']);
}
$_SESSION['error_cart_msg'] = '';
// close session (store variables)
oos_session_close();
if (OOS_LOG_SQL == '1') {
    $dbconn->LogSQL(false);
    // turn off logging
    // output summary of SQL logging results
    $perf = NewPerfMonitor($dbconn);
    echo $perf->SuspiciousSQL();
    echo $perf->ExpensiveSQL();
    echo $perf->InvalidSQL();
}
예제 #10
0
disable_debugging();
$topframe = optional_param('topframe', 0, PARAM_BOOL);
$bottomframe = optional_param('bottomframe', 0, PARAM_BOOL);
$do = optional_param('do', '', PARAM_ALPHA);
require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
$strdatabaseperformance = get_string("databaseperformance");
$stradministration = get_string("administration");
$site = get_site();
$navigation = build_navigation(array(array('name' => $stradministration, 'link' => 'index.php', 'type' => 'misc'), array('name' => $strdatabaseperformance, 'link' => null, 'type' => 'misc')));
if (!empty($topframe)) {
    print_header("{$site->shortname}: {$strdatabaseperformance}", "{$site->fullname}", $navigation);
    exit;
}
if (!empty($bottomframe) or !empty($do)) {
    $perf =& NewPerfMonitor($db);
    $perf->UI($pollsecs = 5);
    exit;
}
?>
<head>
<title><?php 
echo "{$site->shortname}: {$strdatabaseperformance}";
?>
</title>
</head>

<frameset rows="80,*">
   <frame src="dbperformance.php?topframe=true">
   <frame src="dbperformance.php?bottomframe=true">
</frameset>
예제 #11
0
<?php

require_once '../../kernel/setup_inc.php';
if (!$gBitUser->isAdmin()) {
    $gBitSmarty->assign('msg', tra("You dont have permission to use this feature"));
    $gBitSystem->display('error.tpl', NULL, array('display_mode' => 'admin'));
    die;
}
if (defined('DB_PERFORMANCE_STATS') && constant('DB_PERFORMANCE_STATS')) {
    ?>

<h1 style="color:red;">Performance Monitoring is Active!</h1>
<p>Database performance monitoring is a low level, and intensive task. <b>It should not be left on for extended periods of time.</b>

<?php 
} else {
    ?>

<p style="color:red;">To activate database performance, please add to you config/kernel/config_inc.php:<br>
<code>define( 'DB_PERFORMANCE_STATS', TRUE ); </code>

<?php 
}
?>
For more information, see the <a href="http://phplens.com/lens/adodb/docs-perf.htm">ADODB documentation</a>
</p>

<?php 
$perf =& NewPerfMonitor($gBitSystem->mDb->mDb);
$perf->UI($pollsecs = 5);
예제 #12
0
function &adodb_log_sql(&$conn, $sql, $inputarr)
{
    global $ADODB_LOGSQL, $HTTP_SERVER_VARS;
    $conn->fnExecute = false;
    $t0 = microtime();
    $rs =& $conn->Execute($sql, $inputarr);
    $t1 = microtime();
    $a0 = split(' ', $t0);
    $a0 = (double) $a0[1] + (double) $a0[0];
    $a1 = split(' ', $t1);
    $a1 = (double) $a1[1] + (double) $a1[0];
    $time = $a1 - $a0;
    if (!empty($ADODB_LOGSQL)) {
        if (!$rs) {
            $tracer = substr('ERROR: ' . htmlspecialchars($conn->ErrorMsg()), 0, 250);
        } else {
            $tracer = '';
        }
        if (isset($HTTP_SERVER_VARS['HTTP_HOST'])) {
            $tracer .= '<br>' . $HTTP_SERVER_VARS['HTTP_HOST'];
            if (isset($HTTP_SERVER_VARS['PHP_SELF'])) {
                $tracer .= $HTTP_SERVER_VARS['PHP_SELF'];
            }
        } else {
            if (isset($HTTP_SERVER_VARS['PHP_SELF'])) {
                $tracer .= '<br>' . $HTTP_SERVER_VARS['PHP_SELF'];
            }
        }
        //$tracer .= (string) adodb_backtrace(false);
        $tracer = substr($tracer, 0, 500);
        if (is_array($inputarr)) {
            if (is_array(reset($inputarr))) {
                $params = 'Array sizeof=' . sizeof($inputarr);
            } else {
                $params = '';
                $params = implode(', ', $inputarr);
                if (strlen($params) >= 3000) {
                    $params = substr($params, 0, 3000);
                }
            }
        } else {
            $params = '';
        }
        if (is_array($sql)) {
            $sql = $sql[0];
        }
        $arr = array('b' => trim(substr($sql, 0, 250)), 'c' => substr($sql, 0, 4000), 'd' => $params, 'e' => $tracer, 'f' => round($time, 6));
        $saved = $conn->debug;
        $conn->debug = 0;
        if ($conn->dataProvider == 'oci8' && $conn->databaseType != 'oci8po') {
            $isql = "insert into adodb_logsql values({$conn->sysTimeStamp},:b,:c,:d,:e,:f)";
        } else {
            if ($conn->databaseType == 'odbc_mssql') {
                $timer = $arr['f'];
                $sql1 = $conn->qstr($arr['b']);
                $sql2 = $conn->qstr($arr['c']);
                $params = $conn->qstr($arr['d']);
                $tracer = $conn->qstr($arr['e']);
                $isql = "insert into adodb_logsql (created,sql0,sql1,params,tracer,timer) values({$conn->sysTimeStamp},{$sql1},{$sql2},{$params},{$tracer},{$timer})";
                $arr = false;
            } else {
                $isql = "insert into adodb_logsql (created,sql0,sql1,params,tracer,timer) values( {$conn->sysTimeStamp},?,?,?,?,?)";
            }
        }
        $conn->_affected = $conn->affected_rows(true);
        $ok = $conn->Execute($isql, $arr);
        $conn->debug = $saved;
        //$conn->debug=1;
        if (!$ok) {
            $perf =& NewPerfMonitor($conn);
            if ($perf) {
                if ($perf->CreateLogTable()) {
                    $ok = $conn->Execute($isql, $arr);
                }
            } else {
                $ok = $conn->Execute("create table adodb_logsql (\r\n\t\t\t\tcreated varchar(50),\r\n\t\t\t\tsql0 varchar(250), \r\n\t\t\t\tsql1 varchar(4000),\r\n\t\t\t\tparams varchar(3000),\r\n\t\t\t\ttracer varchar(500),\r\n\t\t\t\ttimer decimal(16,6))");
            }
            if (!$ok) {
                ADOConnection::outp("<b>LOGSQL Insert Failed</b>: {$isql}<br>" . $conn->ErrorMsg() . "</br>");
                $ADODB_LOGSQL = false;
            }
        }
    } else {
        //if (!$conn->debug) ADOConnection::outp( "Timer: <b>$sql </b> <font size=-1>$time</font>");
    }
    $conn->fnExecute = 'adodb_log_sql';
    return $rs;
}
예제 #13
0
파일: engine.php 프로젝트: pablius/oob-n1
	/** parses content and outputs */
	public function generateOutput() {
		$this->internalChrono('start_generate');
		// shows debug output from DB
		if ($this->debug) {
			$this->db->debug= true;
			$this->db->LogSQL();
		}

		// check user login
		$this->user= oob_user :: islogued();
$this->internalChrono('user_validate');		
		// url handler
		$this->url= new OOB_urlhandler(false, $this->mode);
		$newurl= $this->config->get('homeelement', 'main');

		if ($this->mode == 'user') {
			if ($this->url->redirectURL() != false)
				$this->url= new OOB_urlhandler($this->url->redirectURL());
				
			if ($this->url->getModule() == "")
			$this->url= new OOB_urlhandler($newurl, $this->mode);
		}
		
		if ($this->mode == 'admin' && $this->url->getModule() == "") 
			$this->url= new OOB_urlhandler('/about', $this->mode);

		$this->perspective = $this->url->getPerspective();
		//end url handler
$this->internalChrono('url_handler');

		$this->t = $this->newTemplate();
$this->internalChrono('template_clone');	
	
		if ($this->mode == 'user')
		$this->t->assign("webdir", $this->webaddress . $this->perspective->safeName());
		
		//security check if admin is logued
			if ($this->mode == 'admin' && $this->user == false && !in_array($this->url->realURI(),array('/','/favicon.ico','/seguridad/login_ajax'))) 
				{
					if (!isset ($_SESSION['redirecting']) && $this->url->realURI() !== '/admin/newtab' ) // no queremos que se rediriga al new_tab, xq no es una pantalla
						{
							$_SESSION['redirecting']= $this->url->realURI();
						}
						
						$this->filename= 'login.tpl';
						$this->url= new OOB_urlhandler("/seguridad/login", 'admin');
				}
			
$this->internalChrono('user_check');

//$this->internalChrono('start_ob');
//		//clean output buffer
//		@ob_clean();
//		
//		//start buffering
//		ob_start();
//
//		// ask the module for the real action 
//		$this->loadModule();
//$this->internalChrono('load_module');
//		//send module output buffer to a var
//		$this->mod_content= ob_get_clean();
//$this->internalChrono('get_content');
//		//clean output buffer again
//	
//$this->internalChrono('end_ob');

// as it seems that eval is faster than normal code, i'll just eval this part
$this->mod_content = eval ("@ob_clean();ob_start();\$this->loadModule(); return ob_get_clean();");
$this->internalChrono('eval_loadmodule');
		
		
	  	if ($this->popup == false) 
 			{
 				eval ("ob_start();return \$this->perspective->generateOutput();ob_end_flush();");
 	 		} 
 		else
			{
				eval ("ob_start();print \$this->mod_content;ob_end_flush();");
			}

	
		
$this->internalChrono('perspective_generate');
		
		if ($this->debug) {
			$this->db->debug= false;
			$this->ExecutionMonitor();
			print "</br></br><hr><h2>Performance Monitor</h2></br></br>";
			$perf= NewPerfMonitor($this->db);
			$perf->UI(5);
		}
		
$this->internalChrono('end_generate');

			$this->db->StartTrans();
				session_write_close();
			$this->db->CompleteTrans();
	

	}