on 01/03/03 7:27 AM, Michael Zornek ([EMAIL PROTECTED]) wrote:

> I'm ether looking to find or build my own open source php based script, that
> would allow you to include a small code chunk on every page of a site and
> then view statistics from the info, on what pages were viewed, how many
> times, etc...
> 
> First, if there are any you know of and want to recommend, please post.
>
> Secondly, if I do build it myself would it be better to write this log to
> file or mysql db? Right now I only get like 200 page views a day but still
> am concerned about resource use since I'm on a shared server.

It depends how detailed you you want it broken down by:

- page
- page and month
- page and week
- page and day
- page and hour
- page and minute
- page and second

Personally, I have two tables:

counters_page (id, url)
counters_hits (page_id, stamp)

My counters.inc script does the following:

- looks to see if the current URL is already listed in counters_page
    - if it is, it grabs the id
    - if not, it inserts and creates a new id
- inserts a record into counters_hits with the page_id, and a unix timestamp
of when that page was hit.

This way, I know the exact second that a page was hit... So I can perform
report on that data, selecting how many hits for each page within the last
week, month, year, minute, 30 seconds, etc etc.

This *IS* a little expensive in terms of data storage though.  Each hit to
the site costs around 20 bytes.  A site I recently launched has attracted
37,000+ hits, so we're already looking at 740k of data.  However, this table
layout IS more economic than recording the entire URL of each hit... instead
we only record the id of the URL.


If I were only concerned with days, or months, I'd choose to store less data
(and may still!!)... for example, a current timestamp is 10 chars long,
wheras storing 2003-03 is only 7 chars (but only cares about the month, not
the day, hour, minute, second, etc).


The key issue with the above design is NOT how long it takes to record the
data (I have never noticed any performance hit on my code, even on a very
busy shared server).  It seems to be (although not drastic AT ALL) at the
point where I choose to report.  It's a LOT of information to plow through,
and it will get worse :)

There are plenty of things I can do though... I can archive reports, I can
cache queries, I can perform monthly analysis, etc etc.  To me, the most
important factor is the data, and I know I've got exactly what I want.


You may also wish to know things like what browser they're using, their IP
address, etc etc, which may be a key reason why you should build your own.


I choose to build my own for the following reasons:

1. learn learn learn
2. keep it tightly integrated with my other admin tools
3. get exactly what I want


Also check out:

http://www.phpbuilder.com/columns/index.php3?cat=5&subcat=32 (logging
category)


 
> Finally, can you call a php script from an ServerSideInclude page??

not sure, but you should check the archives for server side includes and ssi


Justin


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to