What this does is go through my Apache log in my MySQL DB and calculate unique hits, overall hits, amount of bandwidth used per month, and only for the past 3 months! Making sure each month begins and ends on the first and last day of the month, not using timestamps from the current date! Phew. Brain hurts.
$size = $this->Show->Episode->Log->find('all', array('conditions'=>array('Log.filecode'=>$filecodes,'UNIX_TIMESTAMP(`timestamp`) BETWEEN UNIX_TIMESTAMP(DATE_FORMAT(LAST_DAY(DATE_SUB(NOW(), INTERVAL 2 MONTH)), \'%Y%m01000000\')) AND UNIX_TIMESTAMP(DATE_FORMAT(LAST_DAY(NOW()), \'%Y%m%d235959\'))'), 'group'=>array('YEAR(timestamp)', 'MONTH(timestamp)'), 'fields'=>array('Log.*', 'UNIX_TIMESTAMP(timestamp) as timestamp', 'SUM(Log.size) AS size', 'COUNT(*) as hits', 'COUNT(distinct ip) as uhits'), 'order'=>array('timestamp DESC')));




Want To Be Heard? Comment Here!
// I Love Comments, Especially Nice Ones
You can follow any responses to this entry via its RSS comments feed. You may also leave a trackback by clicking this link.