Average Response Time
Hi! I've created a small script to calculate the average response time. It's a class that can be used on any part of your website by simply adding the following lines on the page where you'd like the output to appear:
<?php
include('include/class.response_time.php');
$response_time = new response_time();
echo "<p>Average response time: $response_time->output.</p>";
?>
This would display (as an example):
"Average response time: 120 minutes."
... or ...
"Average response time: 1.4 hours."
... depending on the response time in seconds.
I've attached the class below. I haven't tested it much yet so let me know what you think of it...
<?php
class response_time {
var $dbhost = 'localhost';
var $dbname = 'DATABASE_NAME';
var $dbuser = 'USERNAME';
var $dbpass = 'PASSWORD';
var $output;
function response_time() {
$connection = $this->connect();
$query = "SELECT * FROM ost_ticket ORDER BY ticket_id DESC LIMIT 10";
$result = mysql_query($query);
$o = array();
$i=0;
$seconds = 0;
while( $r=mysql_fetch_assoc($result) ) {
$q = mysql_query("SELECT created FROM ost_ticket_response WHERE ticket_id='".$r."' ORDER BY response_id LIMIT 1") or die(mysql_error());
if ( mysql_num_rows($q) > 0 ) {
$created = strtotime($r);
$updated = strtotime(mysql_result($q,0));
$seconds += $updated - $created;
$i++;
}
}
$avg = $seconds / $i;
$minutes = round( $avg / 60 );
if ( $minutes > 120 ) {
$output = round( ($minutes / 60), 1 ) . " hours";
} else {
$output = "$minutes minutes";
}
$this->output = $output;
}
function connect() {
$connection = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass);
mysql_select_db($dbname,$connection);
return $connection;
}
}
?>