I was just solving a problem for one of my friends, having a weird situation with Drupal statistics module:
His daily popular statistics block wasn't actually showing as "daily". Usually at 5pm, the statistics started to show zero values for top nodes today.
What I found out is that core (Drupal 6) statistics.module is using a typical programmers approach to daily stats. What does it mean if you say "daily"? It means 24 hours = 3600 minutes = 86400 seconds.
So when the daily stats are cleared actually depends on when you enabled the module few days/months/years ago. If you enabled the module around 5pm, it will clear the stats every day around 5pm.
But maybe you want daily stats to be "daily" - meaning from midnight till midnight. How to fix that?
Create a simple script called "fix-time.php" in your Drupal webroot (yes, it could be a module but that's a little bit of an overhead) and type this code inside:
<?php
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
variable_set('statistics_day_timestamp', strtotime('today'));Save the file and open your browser with following address: http://example.com/fix-time.php (Change example.com for your website).
Then remove the file.
What it does? It will set the statistics_day_timestamp to today midnight, causing statistics module to think that the last time it refreshed stats was midnight. From tomorrow, you will always get correct statistics for the whole day - 00:01am -> 23:59pm.
Please note that you should run your cron as often as possible, something around every 5 minutes. Otherwise, this time might slip often...
Jakub is owner and founder of Dynamite Heads. Jakub is a member of Drupal Security Team and supports Czech Drupal community at Drupal.cz








