tags:

views:

59

answers:

2

as the title of the question suggests, my question is simple, which one is better in terms of performance knowing that i'm on a linux shared hosting, siteground.. i'm capable of coding both, i actually coded a one that updates the DB, but from reading around some people suggested to insert and not to update.. any feed back is much appreciated..

thank you.

+1  A: 

Use a database! Since you will have multiple people accessing your site, writing to one file will either mean blocking or having the count overwritten.

By using a database and inserting, you don't have to wait for other clients and you are safely allowing concurrent access. you just get the count by doing a select count(*) from countTbl

Byron Whitlock
Since topic starter will have problems with file blocking then DB solution will kill his server. :) I think that writing to file is better.
Kirzilla
I think handling concurrency through the database is WAY better. Doing one insert per request will not kill his server unless he has facebook like traffic. At that point he will have bigger problems than this little script. Lots of sites do tens of inserts and updates on every request. Have you ever heard of using a DB as a session store? DON'T REDESIGN THE WHEEL, USE A DB
Byron Whitlock
@Kirzilla - Nonsense. What are you basing that on? Databases are optimized for this kind of write situation, and are much faster and more reliable than file locking. The fact that you don't have to **lock** a database table to increment a counter is evidence enough.
zombat
i actually store sessions in DB, my site is built on codeigniter i get around 300 unique visits a day (not that much) but my shared hosting meters (cpu,script excution,blah blah) are still in the green zone.. right now i am using a page views counter that depends on database, i wanted to upgrade it so it'll be a visits counter not a pageviews counter (each IP is logged once for each page).. that's why i asked which one is better i hope this illustrates my needs better, and thank you guys for the responds this was my first post so i am pretty new here
Rami
A: 

What are you storing in the database? If it´s just that one number (the page counter), I would not use a database but if you are storing data for each visitor, a database is the way to go.

jeroen
right now i'm storing visit+1, what i'm planning to do is to store IP so it'll be matched before an insert as "if not_in" ..
Rami
for visit+1 you just need a file, but for visitor's ip's you will need a database.
jeroen