Page 1 of 1

Dynamic page hit counter system - Need advice...

Posted: Sat Jan 01, 2005 7:00 pm
by idotcom
Hi all

I want to offer my members page hit counters for their pages. I have not started because I am not exactly sure of how to go about it yet. I have built several counters before, but not for something like this. Let me tell you how it will be used first.

Every member has his own folder that is created on member signup. The folder name is a generated id. Currently, my members can create/update/delete pages in their folder. What I would like to do, is offer an option to add/remove a hit counter for the pages they have or create. I also need to use an image based counter to display hits on their pages.

What is the best way to do this? If I do database... the size can become huge. I was thinking to use text files that are created based on the file name of the pages they create. But that sounds like it is going to be very complex.

Here is somewhat of a structure...

User sign up: main folder generated + an images folder is created inside for their images

mysite.com/my_members/member_folder_id/(their pages and images folder here)

user created pages:

mysite.com/my_members/member_folder_id/filename.php

mysite.com/my_members/member_folder_id/filename2.php

mysite.com/my_members/member_folder_id/filename3.php

The pages are created and updated using a form page that includes a wysiwyg editor. To create, they enter a filename, create their content, and submit. The files are all created with php extension, but they are not directly accessible to the public. They are basically used to store created content. The main purpose of the files is for the users to be able to copy the html they created whenever they need it, so they can paste into their own sites and so on.

So I think I would need to generate the counter text files based on filename and create the path to enter the image tag into their html.

So this is where I am stuck. I could skip this whole counter thing, but I would really like to offer it. And the counter would need to be addable, deleteable, and resetable... I know... I'm in for a long journey.

So if anyone could help me out in any way... Please do... :?

Thank you in advance, and Happy New Year! :lol:

Posted: Sat Jan 01, 2005 8:14 pm
by feyd
unless you did detailed tracking of the hits (like agents/ips/things of a more unique nature) I don't see why a database would become "huge". To me, it's just one added field (maybe 2, to include the start date possibly) for each page, which would already have a row in the database.

Posted: Sat Jan 01, 2005 9:38 pm
by genetix
if what your meaning by "dynamic" as instant look into flash. Heres a very good tutorial I came accross not to long ago:

http://www.flashkit.com/tutorials/Actio ... /index.php

If you editted it a little your could proabably add an ID field so many websites could run independantly off one script.

Posted: Sun Jan 02, 2005 1:21 pm
by idotcom
Thanks for your reply guys

Well I would prefer to use mysql anyways. It would make my life so much easier. But, I was just thinking that if I had say even 500 members creating and using multiple pages with counters and possibly totalling say an average of 200 hits per member each day... be 100,000 db entries a day. I would also like to log page filename, ip, day, and hour.

I created the table and inserted a long case insert like below. It came out to 80 bytes. 100,000 / 80 / 1024 = 1.22 mb per day.
Could end up with 3 million entries a month...

memfolderid/long_member_page_filename.php | 192.168.0.0 | date("d") | hour

So... I wonder how that would turn out???

Any thoughts??

What kindof strain would that put on the server??


Thanks guys... :)

Posted: Sun Jan 02, 2005 1:31 pm
by feyd
amazingly, 100k entries a day is almost nothing, and easily handled. Remember that the data is actually compressed too. You can store the ip used in 4 bytes, btw. The full timestamp of the transaction can be stored in 4 to 8 bytes (depending on type used)

instead of storing the full path, I'd store a page id.. since each page (across all users) should have an entry in the database already creating that id. (I hate duplicating data across the database). If pressed, I could easily store that entire row in 12, 16, or 20 bytes (uncompressed).

12 = 4 id + 4 ip + 4 timestamp
16 = 8 id + 4 ip + 4 timestamp
20 = 8 id + 4 ip + 4 date + 4 time

Posted: Sun Jan 02, 2005 1:44 pm
by idotcom
thanks for the NEW light! Feyd

I would like to know about the ip thing or compressing the data... But unfortunately... the pages are created direclty in the user folders. I did that because I already have 10 other tables and I didnt want to add the data of the pages. I just store the users folder ID in their row. I also hate data repetition... but hey.. some are better than others at avoiding it :)

This whole counter thing is just a piece of this huge site.

So thanks for any further input/advice you have feyd

Posted: Sun Jan 02, 2005 2:12 pm
by feyd
the ip encoding is very simple. A byte holds 256 possible values. Each component of an ip has a maximum of 256 values. So each number is converted to a single byte (using [php_man]chr()[/php_man])

note that the field needs to be marked binary.