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
2010-01-05 03:34:30
+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
2010-01-05 03:45:52
+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
2010-01-05 04:42:40
+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
2010-01-05 17:53:28
Porbably scales better than memcachehd once you have more than one server running!
James Anderson
2010-01-06 01:44:46