RE: [PHP] counting clicks

2006-11-29 Thread Jay Blanchard
[snip]
Anyone got a script so I can count clicks on adverts. Doesn't have tosve
to 
myqsl or anything just a text file will do.
[/snip]

?php

if(yes == $adClicked){
   $adClickCountFile = fopen(countClick.txt, w);
   $getCount = fgets($adClickCountFile, 4096);
   $newCount = $getCount + 1;
   fwrite($adClickCountFile, $newCount);
   fclose($adClickCountFile);
}
?

YMMV

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] counting clicks

2006-11-29 Thread Richard Lynch
On Wed, November 29, 2006 11:21 am, Jay Blanchard wrote:
 [snip]
 Anyone got a script so I can count clicks on adverts. Doesn't have
 tosve
 to
 myqsl or anything just a text file will do.
 [/snip]

 ?php

 if(yes == $adClicked){
$adClickCountFile = fopen(countClick.txt, w);
$getCount = fgets($adClickCountFile, 4096);
$newCount = $getCount + 1;
fwrite($adClickCountFile, $newCount);
fclose($adClickCountFile);
 }
 ?

This has a race condition where a busy server, or even a not-so-busy
one where 2 people happen to click at the same time, at least one of
them will be missed, at best.

There's also a distinct possiblity of the counter file getting
completely trashed, depending on the OS and its underlying atomicity
of fwrite().

And, finally, you'd need w+ in that fopen() to avoid wiping out the
old data to start with.

For this reason, and more, you're almost-for-sure better off keeping
track in a database which solves all the nasty race condition issues.

YMMV


 YMMV

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] counting clicks

2006-11-29 Thread Jay Blanchard
[snip]
This has a race condition where a busy server, or even a not-so-busy
one where 2 people happen to click at the same time, at least one of
them will be missed, at best.

There's also a distinct possiblity of the counter file getting
completely trashed, depending on the OS and its underlying atomicity
of fwrite().

And, finally, you'd need w+ in that fopen() to avoid wiping out the
old data to start with.

For this reason, and more, you're almost-for-sure better off keeping
track in a database which solves all the nasty race condition issues.
[/snip]

Exactly, YMMV

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] counting clicks

2006-11-29 Thread clive

Ross wrote:
Anyone got a script so I can count clicks on adverts. Doesn't have tosve to 
myqsl or anything just a text file will do.


What about using mysql, but use a memory resident heap table, then every 
once in a while write this to a file or even better to a myisam table





Ta

Ross 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php