|
Cookbook /
SimplePageCounterSummary: A simple page counter of visits to each page
Version: 2009-02-05
Prerequisites: pmwiki-2.2.0
Status:
Maintainer:
Categories: Administration
QuestionCan I keep a simple page counter of visits to each page? Answercounter.phpΔ is a very simple page counter. For every page visited, it will increment a counter, sets a global variable
$PageCount which is also available in the markup as {$PageCount}. The counter file (one file for each page is by default saved as $WorkDir/.counters/$FullName.count.Install
DiscussionIn your pages, you can embed it into a wikipage as follows:
If you want to use it in a template file, simply use the $PageCount variable. The counter will update only when action=browse. So only visitors will increment the counters. If you prefer one Counterfile you may try the modified function (counter-dba.phpΔ) which uses a DBA-Interface. Be aware that the interfaces may vary from provider to provider. DBM usually is not supported anymore by default, but the $db_type may be db3, db4, gdbm or others (see in phpinfo and search for DBA).
See Also
Comments & BugsIs there a limit for the number of hits that can be counted on a single page? Once I reach 2-million-something hits, the count seems to drop back to a 1-million-something figure randomly. Or could this be the result of the file not being properly written when a server PHP process timeout occurrs? --Henning August 22, 2007, at 08:11 AM Very late answer, but yes, the script converts counts to Integers, which maxout around 2-million. Thanks! Maybe there is some way to extend the counting range? Probably not an issue for most pages, it's just my main portal page that is affected. --Henning February 10, 2009, at 08:26 AM ... Hm, never mind, I somehow broke my counter and have now switched over to Cookbook.TotalCounter. --Henning February 20, 2009, at 06:27 AM ... I'm back to SimpleCounter now since TotalCounter has a size limit too. --Henning April 27, 2009, at 09:24 AM Looking at the bit count, I wonder if the 2-million-count-loss issue is really a problem of integer size - 16-bit would be 32768, and 32-bit would be about 2 billion, not 2 million ... any ideas how to fix the script to work above 2 millions? --Henning April 27, 2009, at 10:43 AM As the count on one of my pages just dropped back to a sub-1000 number from a 10000-plus number, there might not be a fixed limit at all, but a different kind of (or additional) problem ... --Henning May 06, 2009, at 05:16 AM The above problem is most likely a race condition updating the counter file, as no locking is done. Here's a version I did that adds file locking, and seems to work for me: (counter-paxed-20091130.phpΔ) paxed November 30, 2009, at 01:40 PM Paxed, many thanks! Your explanation makes perfect sense to me, so I have just installed your version on my system with the full confidence that it will solve the issue once and for all! :-) --Henning December 03, 2009, at 10:56 AM Contributors
This page has been visited 302 times. User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |