Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Looking for Smarty hitcounter plugin w\ instructions

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
dogznbonz
Smarty n00b


Joined: 28 Apr 2004
Posts: 1
Location: Arkansas

PostPosted: Wed Apr 28, 2004 6:11 pm    Post subject: Looking for Smarty hitcounter plugin w\ instructions Reply with quote

Has anyone got a hitcounter plugin? If so could you share it with me and tell me how to use it.
I am very new at smarty and need detailed instructions. Smile

Thanks,
James
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Apr 28, 2004 8:30 pm    Post subject: Reply with quote

To answer your question, I haven't seen any. A counter plugin is not as trivial as it sounds.... there are some inherent problems. I'll try to outline them here for anyone adventurous enough to implement a good one. Wink

The first problem is saving the counter value(s). You could use a flat file, but then you need to setup write access to it. Smarty can write to the $cache and $compile_dir directories, but these are a less-than-ideal place for your hit stats. You must setup a new location for them. This also introduces a file locking issue. Every hit will be trying to update this file, so this could become very unstable with high volumes of traffic.

So with those points in mind, A database driven solution may be optimal. Here is one way to implement it with MySQL:

The MySQL host/user/pass/database settings are probably best hardcoded into the plugin. These could also be kept in a config file for best flexability, but accessing/reading a config file on every hit wouldn't be too desirable just to get a hit recorded and displayed.

setting up MySQL database/user:
Code:

create database HITCOUNT;
grant update,select on HITCOUNT.* to HITUSER@"localhost" identified by 'MYPASS';


The template would look something like this:

Code:

{hitcounter id="foo" assign="hits"}

{* within cached content, use insert? *}
{insert name="hitcounter" id="foo" assign="hits"}


This would spit out the value of the counter identified by "foo", or optionally assign it to a template variable.

The plugin would essentially setup the database connection and execute the following pseudo-code:

Code:

if ( table "foo" does not exist ) {
    CREATE TABLE foo(INT Hits NOT NULL);
    INSERT INTO foo VALUES(1);
    return 1;
} else {
   UPDATE TABLE foo set Hits=Hits+1;
   SELECT Hits from foo;
   (return the value selected)
}


With MySQL, this update will be atomic enough for a hit counter, so no table locking is required. (eg. it is not imperative to get back the same result you just updated)

If you want to guarantee uniqueness across virtual hosts or applications, be sure to prefix something to that affect to the table name.

Have fun!
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Apr 28, 2004 9:59 pm    Post subject: Reply with quote

This may be more than you need, but it is a good tool none-the-less:

http://www.phpopentracker.de/en/index.php

It's features page describes it as:
Quote:
Complete framework for the analysis of website traffic and visitor analysis.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP