/** * Override settingsPage() */ public function settingsPage() { if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.', 'TEXT-DOMAIN')); } $performTest = false; if ($_POST['performTest'] == true) { $performTest = true; } ?> <div class="wrap"> <h2>WPPerformanceTester</h2> <p>WPPerformanceTester performs a series of tests to see how well your server performs. The first set test the raw server performance. The second is WordPress specific. Your results will be displayed and you can see how your results stack up against others.</p> <form method="post" action="<?php echo admin_url('tools.php?page=WPPerformanceTester_PluginSettings'); ?> "> <input type="hidden" name="performTest" value="true"> <input type="submit" value="Begin Performance Test" onclick="this.value='This may take a minute...'"> </form> <?php if ($performTest) { //do test $arr_cfg = array(); $arr_cfg['db.host'] = DB_HOST; $arr_cfg['db.user'] = DB_USER; $arr_cfg['db.pw'] = DB_PASSWORD; $arr_cfg['db.name'] = DB_NAME; $arr_benchmark = test_benchmark($arr_cfg); $arr_wordpress = test_wordpress(); //charting from results goes here ?> <div id="chartDiv"> <div id="legendDiv"></div> <canvas id="myChart" height="400" width="600"></canvas> </div> <p>* Lower (faster) time is better. Please submit your results to improve our industry average data :)</p> <script> jQuery(document).ready(function(){ jQuery.getJSON( "http://wpperformancetester.wphreviews.com/api1.php", function( industryData ) { var ctx = document.getElementById("myChart").getContext("2d"); var data = { labels: ["Math", "String", "Loops", "Conditionals", "MySql", "Server Overall", "WordPress"], datasets: [ { label: "Your Results", fillColor: "rgba(151,187,205,0.5)", strokeColor: "rgba(151,187,205,0.8)", highlightFill: "rgba(151,187,205,0.75)", highlightStroke: "rgba(151,187,205,1)", data: [<?php echo $arr_benchmark['benchmark']['math']; ?> , <?php echo $arr_benchmark['benchmark']['string']; ?> , <?php echo $arr_benchmark['benchmark']['loops']; ?> , <?php echo $arr_benchmark['benchmark']['ifelse']; ?> , <?php echo $arr_benchmark['benchmark']['mysql_query_benchmark']; ?> , <?php echo $arr_benchmark['total']; ?> , <?php echo $arr_wordpress['time']; ?> ] }, { label: "Industry Average", fillColor: "rgba(130,130,130,0.5)", strokeColor: "rgba(130,130,130,0.8)", highlightFill: "rgba(130,130,130,0.75)", highlightStroke: "rgba(130,130,130,1)", data: industryData } ] }; var myChart = new Chart(ctx).Bar(data, { barShowStroke: false, multiTooltipTemplate: "<%= datasetLabel %> - <%= value %> Seconds", }); var legendHolder = document.createElement('div'); legendHolder.innerHTML = myChart.generateLegend(); document.getElementById('legendDiv').appendChild(legendHolder.firstChild); }); }); </script> <div id="resultTable"> <table width="600"> <caption>Server Performance Benchmarks</caption> <thead> <tr> <th width="300">Test</th> <th>Execution Time (seconds)</th> </tr> </thead> <tbody> <tr> <td><span class="simptip-position-right simptip-smooth" data-tooltip="Times 10,000 mathematical functions in PHP">Math</span></td> <td><?php echo $arr_benchmark['benchmark']['math']; ?> </td> </tr> <tr> <td><span class="simptip-position-right simptip-smooth" data-tooltip="Times 10,000 string manipulation functions in PHP">String Manipulation</span></td> <td><?php echo $arr_benchmark['benchmark']['string']; ?> </td> </tr> <tr> <td><span class="simptip-position-right simptip-smooth" data-tooltip="Times 10,000 increments in PHP while and for loops">Loops</span></td> <td><?php echo $arr_benchmark['benchmark']['loops']; ?> </td> </tr> <tr> <td><span class="simptip-position-right simptip-smooth" data-tooltip="Times 10,000 conditional checks in PHP">Conditionals</span></td> <td><?php echo $arr_benchmark['benchmark']['ifelse']; ?> </td> </tr> <tr> <td><span class="simptip-position-right simptip-smooth" data-tooltip="Time it takes to establish a Mysql Connection">Mysql Connect</span></td> <td><?php echo $arr_benchmark['benchmark']['mysql_connect']; ?> </td> </tr> <tr> <td><span class="simptip-position-right simptip-smooth" data-tooltip="Time it takes to select Mysql database">Mysql Select Database</span></td> <td><?php echo $arr_benchmark['benchmark']['mysql_select_db']; ?> </td> </tr> <tr> <td><span class="simptip-position-right simptip-smooth" data-tooltip="Time it takes to query Mysql version information">Mysql Query Version</span></td> <td><?php echo $arr_benchmark['benchmark']['mysql_query_version']; ?> </td> </tr> <tr> <td><span class="simptip-position-right simptip-smooth" data-tooltip="Time it takes for 1,000,000 ENCODE()s with a random seed">Mysql Query Benchmark</span></td> <td><?php echo $arr_benchmark['benchmark']['mysql_query_benchmark']; ?> </td> </tr> </tbody> <tfoot> <tr> <th>Total Time (seconds)</th> <th><?php echo $arr_benchmark['total']; ?> </th> </tr> </tfoot> </table> <br /> <table width="600"> <caption><span class="simptip-position-bottom simptip-multiline simptip-smooth" data-tooltip="Performs 250 Insert, Select, Update and Delete functions through $wpdb">WordPress Performance Benchmark</span></caption> <thead> <tr> <th width="300">Execution Time (seconds)</th> <th>Queries Per Second</th> </tr> </thead> <tfoot> <tr> <td><?php echo $arr_wordpress['time']; ?> </td> <td><?php echo $arr_wordpress['queries']; ?> </td> </tr> </tfoot> </table> <br /> <table width="600"> <caption>Your Server Information</caption> <thead> <tr> <th width="300">Test</th> <th>Result</th> </tr> </thead> <tbody> <tr> <td>WPPerformanceTester Version</td> <td><?php echo $arr_benchmark['version']; ?> </td> </tr> <tr> <td>System Time</td> <td><?php echo $arr_benchmark['sysinfo']['time']; ?> </td> </tr> <tr> <td>Platform</td> <td><?php echo $arr_benchmark['sysinfo']['platform']; ?> </td> </tr> <tr> <td>Server Name</td> <td><?php echo $arr_benchmark['sysinfo']['server_name']; ?> </td> </tr> <tr> <td>Server Address</td> <td><?php echo $arr_benchmark['sysinfo']['server_addr']; ?> </td> </tr> <tr> <td>MySql Server</td> <td><?php echo DB_HOST; ?> </td> </tr> </tbody> </table> </div> <br /> <br /> <form method="post" action="http://wpperformancetester.wphreviews.com" class="basic-grey"> <h2>Share Your Results & Write a Review</h2> <p>All submitted data may be published. Do not include any personal information you do not want publicly listed. Your data helps us maintain industry performance averages and provide users with real web hosting reviews.</p> <input type="submit" value="Share Results Only (Do not fill out form)"> <input type="hidden" name="benchresult" value="<?php echo urlencode(json_encode($arr_benchmark)); ?> "> <input type="hidden" name="wordpressresult" value="<?php echo urlencode(json_encode($arr_wordpress)); ?> "> <h3>What Web Host do you use?</h3> <input type="text" name="host" length="50" placeholder="Company Name"> <h3>Please tell us about your experience</h3> <br />The Good <br /><textarea name="reviewpros" rows="4" cols="50" placeholder="Please list the pros"></textarea> <br />The Bad <br /><textarea name="reviewcons" rows="4" cols="50" placeholder="Please list the cons"></textarea> <br />Anything Else? <br /><textarea name="reviewother" rows="4" cols="50" placeholder="Anything else you would like to add?"></textarea> <h3>How would you rate your web host overall?</h3> <input type="radio" name="rating" value="1"><label>1 - The Worst</label> <input type="radio" name="rating" value="2"><label>2</label> <input type="radio" name="rating" value="3"><label>3</label> <input type="radio" name="rating" value="4"><label>4</label> <input type="radio" name="rating" value="5"><label>5 - The Best</label> <br /><br /> <h3>Your Information</h3> Name <input type="text" name="name" length="50" placeholder="Your Name"> <br />Website <input type="text" name="website" length="50" placeholder="Your Website"> <br />Twitter <input type="text" name="twitter" length="50" placeholder="@username"> <br /><br /> <input type="submit" value="Submit Review + Results"> </form> <?php } ?> </div> <?php }
// ----------------------------------------------------------------------------- // Setup // ----------------------------------------------------------------------------- set_time_limit(120); // 2 minutes $options = array(); // Optional: mysql performance test $options['db.host'] = '127.0.0.1'; $options['db.user'] = '******'; $options['db.pw'] = 'root'; $options['db.name'] = 'classicmodels'; // ----------------------------------------------------------------------------- // Main // ----------------------------------------------------------------------------- // check performance $benchmarkResult = test_benchmark($options); // html output echo "<!DOCTYPE html>\n<html><head>\n"; echo "<style>\n table {\n color: #333; /* Lighten up font color */\n font-family: Helvetica, Arial, sans-serif; /* Nicer font */\n width: 640px;\n border-collapse:\n collapse; border-spacing: 0;\n }\n td, th {\n border: 1px solid #CCC; height: 30px;\n } /* Make cells a bit taller */\n th {\n background: #F3F3F3; /* Light grey background */\n font-weight: bold; /* Make sure they're bold */\n }\n td {\n background: #FAFAFA; /* Lighter grey background */\n }\n </style>\n </head>\n <body>"; echo array_to_html($benchmarkResult); echo "\n</body></html>"; exit; // ----------------------------------------------------------------------------- // Benchmark functions // ----------------------------------------------------------------------------- function test_benchmark($settings) { $timeStart = microtime(true); $result = array(); $result['version'] = '1.1'; $result['sysinfo']['time'] = date("Y-m-d H:i:s");