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