File counter - when just count. DB counter - when visit tracking, depenences, analysis, aggregation.
Read file is really faster, when file is small. Still, there may be a race condition effect, when site is heavy loaded. There is hard to show linked data, if needed. For this needs there is a great solution: Database Management Systems.
Database (with good design) allows to avoid race condition. Also it's a better solution for large amount of linked data structures. It's better, when you need to log visits, referers, etc...
DB Suggestions: you might store counter in one row of global_settings
table and update it within each page visit, or you might get it by registrating each visit in visit
table (with additional data, like IP
, DateTime
, UserID
, etc...) with SELECT COUNT(*) from visit;
.
There is another related topic here.