Work:CPU Exceeded and Slow MySQL Queries Script
From Zoelife4U Wiki
Just like is says, just throw this anywhere in a web accessible directory and don't forget the .php extension.
This tools is handy for identifying the specific problem, see Repair and Optimize All Databases on an Account For information on how to help prevent the need for this script and help the customer keep his databases in order.
Known Bugs:
The Colors are kind of ugly and need some fixing up
<?php /* Loads all the files in CPU Exceeded Logs or Slow MySQL Queries click to view the files contents etc. Copyright (C) 2008 John D Jones III ampvbmVzX0FUX2JsdWVob3N0LmNvbQ== This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/> */ /* Must hand some props to Joe Crown amNyb3duX0FUX2JsdWVob3N0LmNvbQ== For his contibutions, without which, this script would be ugly and buggy. */ //Set some PHP settings first ini_set('register_globals', 'Off'); //Turn this off !! //Let's Do Some Functions to make things easier. //find the home folder function getHome (){ $home_array = $_SERVER['SCRIPT_FILENAME']; $home_split = split ('/', $home_array); $home = "/".$home_split['1']."/".$home_split['2']; return $home; } //Set the path to the cpu_exceeded_logs and mysql_slow_queries function acquirePath($p){ $home = getHome (); if ($p == "cpu") { $thePath = "$home/tmp/cpu_exceeded_logs/"; }elseif($p == "sql") { $thePath = "$home/tmp/mysql_slow_queries/"; } else { $thePath = "$home/tmp/cpu_exceeded_logs/"; //We're going to have a value if is kills us all!! } return $thePath; } // Gotta set up that sleek © whammer.. :D function copyright() { $fw = base64_decode('MjAwOA=='); $ty = date('Y'); if($fw == $ty) { $y = $ty; }else{ $y = $fw."-".$ty; } return $y; } // Set up the variables $home = getHome(); $type = base64_decode($_GET['type']); $f = base64_decode($_GET['f']); $version = "1.7-RELEASE"; // Better checking for directory existence. //$cpu_exceeded_path = cpuPath (); //$mysql_slow_path = sqlPath(); // Do a couple more functions... function displayPage($t, $file) { $path = acquirePath($t); // Sterilize the Input to prevent injections strip_tags($file); stripslashes($file); if(preg_match('/\.\./', $file)) { die('<h1>Access Denied</h1>'); } $c = $path.$file; if(!$theFile = fopen($c, "r")) { die('File Not Found'); // Make sure the the file ($f) is valid } while(!feof($theFile)) { // This is what's loaded in the new window. $contents .= fread($theFile, 8192); echo "\n<p>\n"; echo nl2br($contents); echo "\n</p></body></html>\n"; } fclose($theFile); } function getList($l) { // Now with Error Checking !!! $thePath = acquirePath($l); if(!is_dir($thePath)) { // Stupid if (!chdir) would throw an error, so we use is_dir() for our tests. echo "<h3>No Files Found</h3>"; }else{ chdir($thePath); // Only chdir is the darn thing exists !! if ($l == "cpu") { $h1 = "CPU Exceeded Logs"; }elseif ($l == "sql") { $h1 = "MySQL Slow Queries"; } ?> <h1><?php echo $h1;?></h1> <table cellspacing="15" cellpadding="5"> <tr> <th> Filename </th> <th> Size </th> <th> Modified </th> </tr> <?php foreach (glob('*') as $files) { $fmodtime = date("F d Y H:i:s", filemtime($files)); $fsize = filesize($files); $s = $fsize / 1024; $size = sprintf ("%01.2f", $s); $lenc=base64_encode($l); $fenc=base64_encode($files); echo "<tr>\n<td>\n"; $link = "http://".$_SERVER["HTTP_HOST"].$_SERVER['PHP_SELF']."?type=".$lenc."&f=".$fenc; echo '<a href="#" onclick="window.open (\''.$link.'\', \'\', \'width=925px, height=200px, resizable ,scrollbars=1\')">'.$files.'</a>'; //echo '<a href="'.$_SERVER['PHP_SELF']."?type=".$l."&f=".$files.'" target="_BLANK">'.$files.'</a>'; echo "\n</td>\n<td>$size KB</td>\n<td>$fmodtime</td>\n</tr>\n"; } ?> </table> <?php } } // Now we set up some HTML and Basic CSS echo '<?xml version="1.0" encoding="utf-8"?>'; echo "\n"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head profile="http://www.w3.org/2000/08/w3c-synd/#"> <title>CPU Exceeded Logs and Slow SQL Queries Loader <?php echo $version;?></title> <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" /> <meta name="generator" content="Vim 7.2" /> <style type="text/css"> * { padding: 0; margin: 0; } body { font: 93%/1.0 arial, helvetica, sans-serif; font-size: 14px; } #wrapper { margin: 0 auto; width: 922px; } #leftcolumn { color: #333; border: 1px solid #ccc; background: #CCEDDD; margin: 10px 5px 10px 0px; padding: 10px; min-height: 500px; width: 436px; float: left; } #rightcolumn { float: right; color: #333; border: 1px solid #ccc; background: #DDDEEE; margin: 10px 0px 10px 0px; padding: 10px; min-height: 500px; width: 436px; display: inline; position: relative; } #footer { width: 900px; clear: both; color: #333; border: 1px solid #ccc; background: #CDEEFC; margin: 0px 0px 10px 0px; padding: 10px; } .center { text-align: center } </style> </head> <body> <div id="wrapper"> <?php if (!$type || !$f) { ?> <div id="leftcolumn"> <?php //getcpu(); getList("cpu"); ?> </div> <div id="rightcolumn"> <?php //getsql(); getList("sql"); ?> </div> <?php } //End if(!$type) if ($type == "cpu" || $type == "sql" && $f != "") { displayPage($type, $f); } elseif (!$type && !$f){ $copyright=copyright(); $GPL='<a href="http://www.gnu.org/licenses/gpl-3.0.html" title="GPL 3.0">GPL 3.0</a>'; $usage=memory_get_usage(); //Please leave this for debug purposes. echo "<div id='footer'> <p> <small> <span class='center'>Version $version © $copyright $GPL $usage</span> </small> </p> </div>"; ?> </div> </body> </html> <?php } else { ?> </div> </body> </html> <?php // We'll never get this far anymore. } ?>
The CSS Uncompressed, for developers use
Compress at CSSDrive.Com
* { padding: 0; margin: 0; } body { font: 93%/1.0 arial, helvetica, sans-serif; font-size: 14px; } #wrapper { margin: 0 auto; width: 922px; } #leftcolumn { color: #333; border: 1px solid #ccc; background: #CCEDDD; margin: 10px 5px 10px 0px; padding: 10px; min-height: 500px; width: 436px; float: left; } #rightcolumn { float: right; color: #333; border: 1px solid #ccc; background: #DDDEEE; margin: 10px 0px 10px 0px; padding: 10px; min-height: 500px; width: 436px; display: inline; position: relative; } #footer { width: 900px; clear: both; color: #333; border: 1px solid #ccc; background: #CDEEFC; margin: 0px 0px 10px 0px; padding: 10px; .center { text-align: center }