Topic awaiting preservation: average hits with PHP (Page 1 of 1) |
|
---|---|
Bipolar (III) Inmate From: London |
posted 04-26-2002 21:36
Hello all |
Maniac (V) Lord Mad Scientist Sovereign of all the lands Ozone and just beyond that little green line over there... From: Stockholm, Sweden |
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. |
Bipolar (III) Inmate From: London |
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? |
Maniac (V) Lord Mad Scientist Sovereign of all the lands Ozone and just beyond that little green line over there... From: Stockholm, Sweden |
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. |
Maniac (V) Mad Scientist From: 100101010011 <-- right about here |
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. |