Closed Thread Icon

Topic awaiting preservation: average hits with PHP (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12192" title="Pages that link to Topic awaiting preservation: average hits with PHP (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: average hits with PHP <span class="small">(Page 1 of 1)</span>\

 
mogge
Bipolar (III) Inmate

From: London
Insane since: Mar 2002

posted posted 04-26-2002 21:36

Hello all

I've done a PHP script that counts users when accessing the indexpage like index.php?id=139 then a counter goes up on that user and their webpage moves up in a top list, this will be pretty unfair if someone has joined 3 months earlier and already has refered 200 people to my site, my problem is that I need to make a script that counts average of hits in for ever day or hour or something, does anyone has any idea in how do do this? or have any other suggestion in how to make a toplist like this fair to both new users and old users.

Thanks.


3D Link Resources!

DocOzone
Maniac (V) Lord Mad Scientist
Sovereign of all the lands Ozone and just beyond that little green line over there...

From: Stockholm, Sweden
Insane since: Mar 1994

posted posted 04-26-2002 22:29

I experimented with a PHP counter script that worked this way, but I had it on my "handson" pages and periodically two people would arrive at the same second and the count got all messed up. I haven't dug into this yet, but I think it's something like flock() to lock that file while it's being updated, but do please check the PHP help files for how this works, I've not used it yet, so I'm talking out my ass, heh.

I'm not sure how you'd do this without building a full log file of not only how many visits came in, but also the times that each visit happened. (Hmm, that should work, shouldn't it?) So, it seems that you need more than a counter, you need to save a new line for each visit, with the date and time it occured. Then your script could just look at the hits from the last day/week/month, you choose. You might also need an admin tool to step through and clean out all the out-of-date entries, better to do that yourself rather than trying to have a script clean up after itself each time a page is accessed. (When you clean up, might be a good idea to save the first hit date, as well as a hit total. Could be useful info.)

Your pal, -doc-

mogge
Bipolar (III) Inmate

From: London
Insane since: Mar 2002

posted posted 04-26-2002 22:40

Hiya, Thanks for the thoughts, I'm gonna have another go and see what happends, I think I forgot to mention that I use mySQL to store all the data, I think this is easier, don't you think?


3D Link Resources!

DocOzone
Maniac (V) Lord Mad Scientist
Sovereign of all the lands Ozone and just beyond that little green line over there...

From: Stockholm, Sweden
Insane since: Mar 1994

posted posted 04-26-2002 23:09

Oh yah, MySQL makes this much easier. Just store all the hits from each, only one more field. If you wanted at this point, you could also purge the hits older than today-x, this should work without too much burden on the server. I'd consider not having this update second by second, but instead do some kind of cron job to update the listings once a night.

Your pal, -doc-

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 04-27-2002 02:33

Yeah like Doc said. I'd have your output write to a flat file that you include that may be updated every half hour or something like that. (Everytime the page is hit as you are doing the db insert with the refferer data do a quick filemtime (file last modified) and see when it was last modified, if it's over a half hour (or whatever) then that once have it do an update the top refferers included file. That may be easier than doing the crontab. You can even use the data returned from the filemtime to write out some sort of "top refferers as of: (returned timestamp, maybe run through the date funtion for formatting)" so you're getting some viewable functionality when you do it.

A similar method with a file that you just tweak everytime you purge the db could allow you to do something similar for the once a week issue.

This sounds a little confusing I know, but what this does is that your potentially going to have a database of thousands of entries it prevents you from having to run a Query every time you generate the page.



.:[ The Tao of Steve ]:.
Be Desireless
Be Excellent
Be Gone
...................................

« BackwardsOnwards »

Show Forum Drop Down Menu