?? adodb-perf.inc.php
字號:
case 'poll2': echo "<pre>"; $this->Poll($pollsecs); break; case 'dosql': if (!$allowsql) break; $this->DoSQLForm(); break; case 'viewsql': if (empty($_GET['hidem'])) echo " <a href=\"?do=viewsql&clearsql=1\">Clear SQL Log</a><br>"; echo($this->SuspiciousSQL($nsql)); echo($this->ExpensiveSQL($nsql)); echo($this->InvalidSQL($nsql)); break; case 'tables': echo $this->Tables(); break; } global $ADODB_vers; echo "<p><div align=center><font size=1>$ADODB_vers Sponsored by <a href=http://phplens.com/>phpLens</a></font></div>"; } /* Runs in infinite loop, returning real-time statistics */ function Poll($secs=5) { $this->conn->fnExecute = false; //$this->conn->debug=1; if ($secs <= 1) $secs = 1; echo "Accumulating statistics, every $secs seconds...\n";flush(); $arro =& $this->PollParameters(); $cnt = 0; set_time_limit(0); sleep($secs); while (1) { $arr =& $this->PollParameters(); $hits = sprintf('%2.2f',$arr[0]); $reads = sprintf('%12.4f',($arr[1]-$arro[1])/$secs); $writes = sprintf('%12.4f',($arr[2]-$arro[2])/$secs); $sess = sprintf('%5d',$arr[3]); $load = $this->CPULoad(); if ($load !== false) { $oslabel = 'WS-CPU%'; $osval = sprintf(" %2.1f ",(float) $load); }else { $oslabel = ''; $osval = ''; } if ($cnt % 10 == 0) echo " Time ".$oslabel." Hit% Sess Reads/s Writes/s\n"; $cnt += 1; echo date('H:i:s').' '.$osval."$hits $sess $reads $writes\n"; flush(); if (connection_aborted()) return; sleep($secs); $arro = $arr; } } /* Returns basic health check in a command line interface */ function HealthCheckCLI() { return $this->HealthCheck(true); } /* Returns basic health check as HTML */ function HealthCheck($cli=false) { $saveE = $this->conn->fnExecute; $this->conn->fnExecute = false; if ($cli) $html = ''; else $html = $this->table.'<tr><td colspan=3><h3>'.$this->conn->databaseType.'</h3></td></tr>'.$this->titles; $oldc = false; $bgc = ''; foreach($this->settings as $name => $arr) { if ($arr === false) break; if (!is_string($name)) { if ($cli) $html .= " -- $arr -- \n"; else $html .= "<tr bgcolor=$this->color><td colspan=3><i>$arr</i> </td></tr>"; continue; } if (!is_array($arr)) break; $category = $arr[0]; $how = $arr[1]; if (sizeof($arr)>2) $desc = $arr[2]; else $desc = ' '; if ($category == 'HIDE') continue; $val = $this->_DBParameter($how); if ($desc && strncmp($desc,"=",1) === 0) { $fn = substr($desc,1); $desc = $this->$fn($val); } if ($val === false) { $m = $this->conn->ErrorMsg(); $val = "Error: $m"; } else { if (is_numeric($val) && $val >= 256*1024) { if ($val % (1024*1024) == 0) { $val /= (1024*1024); $val .= 'M'; } else if ($val % 1024 == 0) { $val /= 1024; $val .= 'K'; } //$val = htmlspecialchars($val); } } if ($category != $oldc) { $oldc = $category; //$bgc = ($bgc == ' bgcolor='.$this->color) ? ' bgcolor=white' : ' bgcolor='.$this->color; } if (strlen($desc)==0) $desc = ' '; if (strlen($val)==0) $val = ' '; if ($cli) { $html .= str_replace(' ','',sprintf($this->cliFormat,strip_tags($name),strip_tags($val),strip_tags($desc))); }else { $html .= "<tr$bgc><td>".$name.'</td><td>'.$val.'</td><td>'.$desc."</td></tr>\n"; } } if (!$cli) $html .= "</table>\n"; $this->conn->fnExecute = $saveE; return $html; } function Tables($orderby='1') { if (!$this->tablesSQL) return false; $savelog = $this->conn->LogSQL(false); $rs = $this->conn->Execute($this->tablesSQL.' order by '.$orderby); $this->conn->LogSQL($savelog); $html = rs2html($rs,false,false,false,false); return $html; } function CreateLogTable() { if (!$this->createTableSQL) return false; $table = $this->table(); $sql = str_replace('adodb_logsql',$table,$this->createTableSQL); $savelog = $this->conn->LogSQL(false); $ok = $this->conn->Execute($sql); $this->conn->LogSQL($savelog); return ($ok) ? true : false; } function DoSQLForm() { $PHP_SELF = $_SERVER['PHP_SELF']; $sql = isset($_REQUEST['sql']) ? $_REQUEST['sql'] : ''; if (isset($_SESSION['phplens_sqlrows'])) $rows = $_SESSION['phplens_sqlrows']; else $rows = 3; if (isset($_REQUEST['SMALLER'])) { $rows /= 2; if ($rows < 3) $rows = 3; $_SESSION['phplens_sqlrows'] = $rows; } if (isset($_REQUEST['BIGGER'])) { $rows *= 2; $_SESSION['phplens_sqlrows'] = $rows; } ?><form method="POST" action="<?php echo $PHP_SELF ?>"><table><tr><td> Form size: <input type="submit" value=" < " name="SMALLER"><input type="submit" value=" > > " name="BIGGER"></td><td align=right><input type="submit" value=" Run SQL Below " name="RUN"><input type=hidden name=do value=dosql></td></tr> <tr> <td colspan=2><textarea rows=<?php print $rows; ?> name="sql" cols="80"><?php print htmlspecialchars($sql) ?></textarea> </td> </tr> </table></form><?php if (!isset($_REQUEST['sql'])) return; $sql = $this->undomq(trim($sql)); if (substr($sql,strlen($sql)-1) === ';') { $print = true; $sqla = $this->SplitSQL($sql); } else { $print = false; $sqla = array($sql); } foreach($sqla as $sqls) { if (!$sqls) continue; if ($print) { print "<p>".htmlspecialchars($sqls)."</p>"; flush(); } $savelog = $this->conn->LogSQL(false); $rs = $this->conn->Execute($sqls); $this->conn->LogSQL($savelog); if ($rs && is_object($rs) && !$rs->EOF) { rs2html($rs); while ($rs->NextRecordSet()) { print "<table width=98% bgcolor=#C0C0FF><tr><td> </td></tr></table>"; rs2html($rs); } } else { $e1 = (integer) $this->conn->ErrorNo(); $e2 = $this->conn->ErrorMsg(); if (($e1) || ($e2)) { if (empty($e1)) $e1 = '-1'; // postgresql fix print ' '.$e1.': '.$e2; } else { print "<p>No Recordset returned<br></p>"; } } } // foreach } function SplitSQL($sql) { $arr = explode(';',$sql); return $arr; } function undomq($m) { if (get_magic_quotes_gpc()) { // undo the damage $m = str_replace('\\\\','\\',$m); $m = str_replace('\"','"',$m); $m = str_replace('\\\'','\'',$m); } return $m;} /************************************************************************/ /** * Reorganise multiple table-indices/statistics/.. * OptimizeMode could be given by last Parameter * * @example * <pre> * optimizeTables( 'tableA'); * </pre> * <pre> * optimizeTables( 'tableA', 'tableB', 'tableC'); * </pre> * <pre> * optimizeTables( 'tableA', 'tableB', ADODB_OPT_LOW); * </pre> * * @param string table name of the table to optimize * @param int mode optimization-mode * <code>ADODB_OPT_HIGH</code> for full optimization * <code>ADODB_OPT_LOW</code> for CPU-less optimization * Default is LOW <code>ADODB_OPT_LOW</code> * @author Markus Staab * @return Returns <code>true</code> on success and <code>false</code> on error */ function OptimizeTables() { $args = func_get_args(); $numArgs = func_num_args(); if ( $numArgs == 0) return false; $mode = ADODB_OPT_LOW; $lastArg = $args[ $numArgs - 1]; if ( !is_string($lastArg)) { $mode = $lastArg; unset( $args[ $numArgs - 1]); } foreach( $args as $table) { $this->optimizeTable( $table, $mode); } } /** * Reorganise the table-indices/statistics/.. depending on the given mode. * Default Implementation throws an error. * * @param string table name of the table to optimize * @param int mode optimization-mode * <code>ADODB_OPT_HIGH</code> for full optimization * <code>ADODB_OPT_LOW</code> for CPU-less optimization * Default is LOW <code>ADODB_OPT_LOW</code> * @author Markus Staab * @return Returns <code>true</code> on success and <code>false</code> on error */ function OptimizeTable( $table, $mode = ADODB_OPT_LOW) { ADOConnection::outp( sprintf( "<p>%s: '%s' not implemented for driver '%s'</p>", __CLASS__, __FUNCTION__, $this->conn->databaseType)); return false; } /** * Reorganise current database. * Default implementation loops over all <code>MetaTables()</code> and * optimize each using <code>optmizeTable()</code> * * @author Markus Staab * @return Returns <code>true</code> on success and <code>false</code> on error */ function optimizeDatabase() { $conn = $this->conn; if ( !$conn) return false; $tables = $conn->MetaTables( 'TABLES'); if ( !$tables ) return false; foreach( $tables as $table) { if ( !$this->optimizeTable( $table)) { return false; } } return true; } // end hack }?>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -