hit counter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

hit counter

Post by Vegan »

I was thinking that a simple hit counter would be one way to track various users

the classes are adblock users, users who are not using it and the worst, repeat offenders

so I suspect an array can handle the 3 cases

Code: Select all

$survey = array[3]
so now I need a mechanism to read the file, ideally the file is in docroot, so the filename may need to be massaged a bit

Code: Select all

$phile = fopen("survey.txt", "r") or die("error opening survey.txt") 
inhaling the file into the array

Code: Select all

$survey = fgets($phile);
so is this the right track for an array?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: hit counter

Post by requinix »

You want a file? A database would be better for this. No worrying about concurrency and file locking.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: hit counter

Post by Vegan »

only 3 boxes to increment, can PHP lock a file for a write then release it fast?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: hit counter

Post by Celauran »

http://php.net/manual/en/function.flock.php

Doesn't make it the right tool for the job
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: hit counter

Post by Vegan »

Celauran wrote:http://php.net/manual/en/function.flock.php

Doesn't make it the right tool for the job
Got a better solution?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: hit counter

Post by Celauran »

As requinix already pointed out, a database makes much more sense here.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: hit counter

Post by Christopher »

Vegan wrote:ideally the file is in docroot, so the filename may need to be massaged a bit
I agree that this is what databases are made for. Ideally files like this are not in a publicly accessible directory. If you insist on using a file (I know how you are), I'd recommend a file for each counter. See if you can find a Perl style counter script in PHP with file locking and retry.
(#10850)
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: hit counter

Post by Vegan »

I am sticking with NoSQL as I do not feel like spending cash speculatively

Amazon has some new ads, all JS based so I am stuffing them into a bunch of PHP #includes

i am testing some on the home page, and on a few others, to see if I can make a few more pesos
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: hit counter

Post by Christopher »

Vegan wrote:I am sticking with NoSQL as I do not feel like spending cash speculatively
Just to clarify for anyone else reading:

1. You are not actually using a NoSQL solution -- which are key based record stores that use a server just like SQL databases' do. You are using a file based solution. And as mentioned above, there are even file based SQL solutions like SQLite.
2. Databases come standard with almost all kinds of hosting at no extra cost .. so there is no speculation involved.
Vegan wrote:Amazon has some new ads, all JS based so I am stuffing them into a bunch of PHP #includes
Well ... that's a solution ...
Vegan wrote:i am testing some on the home page, and on a few others, to see if I can make a few more pesos
Excellent!
(#10850)
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: hit counter

Post by Vegan »

Given the capabilities with PHP are rather extensive, all I can do is work on ideas and try to find solutions.

I was thinking the PHP SWITCH and some string massaging would be as good as any.

GPU ads are on my site in many places, but now that i have more regions to serve, I can use PHP switch for some ads that apply to other locales
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: hit counter

Post by Christopher »

Vegan wrote:Given the capabilities with PHP are rather extensive, all I can do is work on ideas and try to find solutions.
I couldn't have said it better or worse ...
Vegan wrote:I was thinking the PHP SWITCH and some string massaging would be as good as any.
We discussed using some simple convention using locales to select ads -- rather than a switch(). There almost always a data driven approach that is superior to using switch().
Vegan wrote:GPU ads are on my site in many places, but now that i have more regions to serve, I can use PHP switch for some ads that apply to other locales
Congrats on having more regions!
(#10850)
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: hit counter

Post by Vegan »

One of the problems I face, Amazon makes it harder than need be to serve the global market

This forces me to consider strategies galore. This way I have a clearer understanding of solutions for the problem.

one problem, amazons ad widget does not work past 4 wide which is fine for postage stamp web sites, my site is designed for widescreen users

https://hardcore-games.azurewebsites.net/wp/hw/psu.php is an example of the maximum width and even the JS function for custom width does not help

I would have been happier with 8 wide so I could work on a new footer

excel and php both like csv type containers, which is fine if i want to use excel to make a pie chart
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply