1

I need advice on what database fields should I create for a script that records visitor statistics.

So far I have

ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
os varchar(10) default NULL,
time datetime NOT NULL default '0000-00-00 00:00:00',
ip varchar(40) default NULL,
host varchar(150) default NULL,
browser varchar(50) default NULL,
os varchar(20) default NULL,
referrer text,
search text,
language varchar(5) default NULL,
screenres varchar(15) default NULL,
PRIMARY KEY (ID),
KEY time (time)

Basically I want to record as much data as possible for each visit, but at the same time keep the table access fast because it will have many records...

Do you think I should store the os + browser into a single field in raw format (value of $_SERVER['HTTP_USER_AGENT']), and determine the os and browser on output ?

1
  • 1
    Well, in the end, it depends on what you want to do with the data and what you want to know about the user... So that's a quite abstract action.
    – Quasdunk
    Aug 7, 2011 at 21:16

2 Answers 2

0

There is still quite a lot that needs to be answered before anyone here can give you a clearer answer.

  1. What is this all going to be used for?

  2. Is this going to log every page visited or just the initial 'landing page' of the visitor?

Also, yes you could just store the HTTP_USER_AGENT in one field and process on output (if needed at the time), are you going to record how long the user stays on your page to see if it was a mistake or if they are reading it. From there you could look at maybe seeing if they click at least one other link on your site.

As for speed of it storing, well that will heavily depend on how many visitors you expect within a certain period of time, once you have a figure like that you could look at simulating that many people accessing your site whilst seeing how long it takes for you to get a bottleneck.

0

In my opinion "keep(...)access fast" and the word "table" don't fit in one sentence. Simply, because logging visits to DB is always slow in relation to any dedicated logging method.

Best way - use the native logging for your script engine, for example syslog.

I guess you're using PHP, so best results can be easily achieved with simply fopen() flock() fwrite() calls. Then - you can simply log almost EVERYTHING about your visitor: cookies, get, post, session, whole server array (which simply contain fields like referrer or ip). It's also useful to log script execution time and script errors if any.

As for me, I use PHP Log2Files Advanced Logger, which logs as text or as binary - and this is really fastest solution :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.