THINK YOUR SERVER IS RUNNING SLOW? - Aug 6th, 2010
|
You can display the total execution time on your web page with this code:
<?php showExecuteSeconds() ?> seconds
Or for a more verbose description of both connection success or failure and the time it took to connect, here’s a script Dave Edis of Interactive Tools wrote that times your MySQL connection speed.
Paste the following into a blank PHP doc, change the hostname, username and password to your information, and upload it to the root directory of your server (where you normally run your .PHP docs from) and open the file in your browser.
<?PHP
// MYSQL INFO $hostname = "localhost"; $username = "root"; $password = "";
// get start time $START_TIME = microtime();
// enable error checking if (!defined('E_STRICT')) { define('E_STRICT', 2048); } // define E_STRICT for PHP < 5 error_reporting(E_ALL | E_STRICT); // display all errors ini_set('display_errors', '1'); ini_set('display_startup_errors', '1');
// timer function function showExecuteSeconds() { $endTime = microtime();
list($start_msec, $start_sec) = explode(" ", $GLOBALS['START_TIME']); // START_TIME is set in init.php list($end_msec, $end_sec) = explode(" ", $endTime);
$diff_sec = intval($end_sec) - intval($start_sec); $diff_msec = floatval($end_msec) - floatval($start_msec); $totalTime = floatval( $diff_sec ) + $diff_msec; $value = sprintf("%0.2f", $totalTime);
print "Total Time: $value seconds<br /><br />\n"; }
// print "<h1>Testing MySQL Speed</h1>"; showExecuteSeconds();
// connect to mysql print "Connecting to MySQL...<br />"; mysql_connect($hostname, $username, $password) or die("Error connecting to MySQL: " . mysql_error()); showExecuteSeconds();
// print "Done";
?>
|
The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact
Interactive Tools for information on the downloading of the software or the purchasing of licenses.