track response size in stats

This commit is contained in:
Colin Mitchell 2012-04-25 21:24:41 -04:00
parent ce984610a7
commit e9febc25c2
3 changed files with 20 additions and 7 deletions

View File

@ -98,6 +98,19 @@ class Cache {
return $cache;
}
public function size($key, $expiration = 3600) {
if ( !is_dir($this->dir) OR !is_writable($this->dir)) {
return FALSE;
}
$cache_path = $this->_name($key);
if (!@file_exists($cache_path)) {
return FALSE;
}
return filesize($cache_path);
}
private function mkdir_p($path) {
if (!is_dir($path)) {

View File

@ -62,9 +62,6 @@ class GopherGetter {
$this->errno = "";
$this->logTraffic($this->host, $this->path);
$this->result = $this->cache->get($this->key);
if ( $this->result === FALSE ) {
error_log("tcp://$this->host:$this->port\t$this->input");
@ -91,9 +88,14 @@ class GopherGetter {
$this->cache->set($this->key, $this->result);
}
$this->logTraffic($this->host, $this->path);
return TRUE;
}
function size() {
return $this->cache->size($this->key);
}
function logTraffic($host, $selector) {
/* error_log(LOG_STATS);
if ( ! isset(LOG_STATS) || LOG_STATS != true ) {
@ -106,15 +108,12 @@ class GopherGetter {
'hostname' => $host,
'selector' => $selector,
'remote_ip' => $ip_address,
'filesize' => $this->size(),
'request_at' => DB::sqleval("NOW()")
));
}
function size() {
return strlen($this->result);
}
};
?>

View File

@ -3,6 +3,7 @@ CREATE TABLE traffic (
hostname varchar(100) NOT NULL,
selector varchar(100) NOT NULL,
remote_ip INT UNSIGNED NOT NULL,
filesize INT UNSIGNED NOT NULL DEFAULT 0,
request_at datetime NOT NULL
);