tags:

views:

56

answers:

2

I wanted to know what would be a good way for storing the information required by a something like a hit counter. I was wondering if this was possible using some session-like technique, but available to everyone. I am concerned about speed/performance, and not memory usage since the data to be store is minimal.

+2  A: 

This is the sort of thing people use APC and/or memcached for.

Frank Farmer
+1. You can optionally persist the counter to disk/DB every N-minutes via cron, if you need to. Redis may also be worth a look in that case, as it has persistence built in.
oops
+1  A: 

Store it in a database!

If you app doesnt already use a DB you almost certainly have sqlite installed as part of your php installtion. Its about 10 lines of code to connect and read the value.

If you app already uses a db its one extra table with one extra column.

James Anderson
+1. A db is definitely an adequate solution for small-scale applications, and it handles concurrency, unlike a simple file-based solution. It may not perform quite as well as memcached etc., but it might be worth keeping things simple and sticking with your existing datastore (rather than adding a second) in some contexts.
Frank Farmer
Porbably scales better than memcachehd once you have more than one server running!
James Anderson