And the fix isn't that hard, either.
First of all, whoever wrote that magazine article needs to have their knuckles rapped from now until kingdom come! To be completely safe, you have to lock the file, but the example makes it so much worse by closing and reopening the file, which greatly lengthens the time when the file is "at risk".
So for starters:
function countHits($file)
{
if($fd = @fopen($file, "r+"))
{
$counter = fgets($fd, 1024);
rewind($fd);
}
elseif (! ($fd = fopen($file,"w")))
{ // can't create, either
return;
}
fwrite($fd, $counter + 1);
fclose($fd);