Here's an idea for testing purposes to determine why it's counting low, too.... Have your PHP script write to two files --- one that contains the number as it is now, and one that writes the number and a timestamp on a new line each time it's accessed. This way, you can scan down the list to see where the error occurs, and then cross-check it with your Apache logs at the time indicated by the timestamp. On 4/20/07, Amos Vryhof <avryhof@xxxxxxxxxxxxxxxxx> wrote:
Thanks Daniel, I will switch that. Like I said, I copied it from someone's (obviously erroneous) example and didn't want to "mess it up"... I usually use variable++ for increments. Daniel Brown wrote: > One not, Amos, is that instead of using $count += 1, you should just do > $count++. That will automatically increment the number. > > On 4/20/07, Amos Vryhof <avryhof@xxxxxxxxxxxxxxxxx> wrote: >> >> I build websites for a lot of people, and many of them want statistics >> and hit counters for their websites. >> >> Since not all of them are on a dedicated or virtual host, I cobbled >> together a script that builds log files, and displays a graphical hit >> counter, and another script that runs Webalizer and goes to the report. >> >> My dilemma is that the hit counter portion of the script works at first, >> then at some point loses track, and displays a number that is way off >> from the actual number. >> >> I was originally using code that read the number from a text file, added >> 1 to it, then wrote it back using file_get/put_contents. >> >> Since then I have changed to >> >> if (file_exists($logfile)) { >> $fp = fopen("$logfile", "r+"); >> flock($fp, 1); >> $count = fgets($fp, 4096); >> $count += 1; >> fseek($fp,0); >> fputs($fp, $count); >> flock($fp, 3); >> fclose($fp); >> } else { >> echo "Can't find file, check '\$logfile'<BR>"; >> } >> >> which I found in an example somewhere (maybe on the example code page?) >> but that seems to lose track as well. >> >> The server is hosted by AIT, running Apache 1.3.34. >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107