I am doing a logging accesses -script to my web page and I have noticed a little problem.
I store HTTP_USER_AGENT and unix timestamp to textfile. Each row is one unique hit and contains information in followind kind of format "HTTP_USER_AGENT||time".
When the script, for example, provides hits per hour it will check line by line when the visitor came and stores the data into an array. Below is a piece of code which I have used:
$content_of_stats = file(stats.log);
foreach ($content_of_stats as $content_of_stat) {
list($browser, $time) = explode('||', $content_of_stat);
$hour = date(G, $time);
$hours[$hour]++;
}
This kind of method works fine untill there are about 50 000 rows in the file (it will come really slow).
What kind of method should I use to loop through the file when getting the information. Or should I use some kind of other method when storing information.
There is a test version at http://lambda.nic.fi/~zenith/counter/stat.php?f=count.log. It is still under development so it won't work 100% correctly.