wolfmanp Posted January 23, 2007 Share Posted January 23, 2007 Posted this in the php help section but thought some mysql experts might know a bit more.Hi there, I'm writing a counter for pages on a high traffic website. My diea is to have text files for every item and then update thise files by adding a 1 to it so the size increases by 1 byte every hit. Then when the filesize goes over say 15 bytes then I do an update to the DB adding 15 to the hits column to save having to do a DB update call on every hit.My question is if I'm doing a file IO every page display will this bog down the sytem moreso then doing a mysql update? Do you guys think my idea is a good one?Actually writing this out I think I've thought of a better idea. What about a cron job every 10 minutes or so which scans the db and adds all the hits to the db every 10 minutes. This would save on extremely popular pages that get over a thousand hits in that time. Rather than doing around 60 updates in 10 minutes it would do 1 update. What do you guys think? Quote Link to comment Share on other sites More sharing options...
artacus Posted January 24, 2007 Share Posted January 24, 2007 You're better off just writing to the db. You're not speeding anything up because you still have to do all the file i/o. So you're just adding a layer of complexity. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 24, 2007 Share Posted January 24, 2007 Let the DB handle this, I agree -- no need to "fake" a counter with the file system. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 24, 2007 Share Posted January 24, 2007 In fact, if you use INSERT ON DUPLICATE KEY UPDATE, you can have a realy simple counter. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.