DSGameMaker Posted December 28, 2009 Share Posted December 28, 2009 Hi folks, I know there's 2 ways you can build a download counter: A file to which you write, or writing to a specific row/field in a MySQL field. As this php page for recording the download is going to be used alot, like 1000 times a day, it has to be efficient. All it will be doing is: Take the number of current downloads (GET), add 1, save it (SET). I know file handling and I/O is slow but how slow is SQL in comparison.. is it worth creating an entire query and session for that or use the filesystem. I would like your advice on which is better to use. Regards, - James Quote Link to comment https://forums.phpfreaks.com/topic/186471-download-counter/ Share on other sites More sharing options...
Daniel0 Posted December 28, 2009 Share Posted December 28, 2009 A real database will be better. It'll support concurrent writes better because if the table is locked, it'll just queue queries like this: UPDATE files SET downloads=downloads+1 WHERE id=42; If you are writing to a file you risk getting incorrect results with many concurrent requests. If you are concerned about making too many writes to the database, you can use something like APC to cache download counts and only write the changes to the database every 10 minutes for instance. Quote Link to comment https://forums.phpfreaks.com/topic/186471-download-counter/#findComment-984812 Share on other sites More sharing options...
DSGameMaker Posted December 28, 2009 Author Share Posted December 28, 2009 Alright. I'll use the database, as I can log other downloads therewith too. Thanks. I want to know about APC, I thought I knew everything useful about SQL but this has caught my eye. Have you got a link to something on php.net? Ta. Quote Link to comment https://forums.phpfreaks.com/topic/186471-download-counter/#findComment-985145 Share on other sites More sharing options...
Daniel0 Posted December 28, 2009 Share Posted December 28, 2009 http://php.net/apc Quote Link to comment https://forums.phpfreaks.com/topic/186471-download-counter/#findComment-985152 Share on other sites More sharing options...
DSGameMaker Posted December 28, 2009 Author Share Posted December 28, 2009 I bookmarked it but will not be using it right now, looks similar to cron job stuffs. Thanks for the help. Now, back to that substr efficiency thread.. Quote Link to comment https://forums.phpfreaks.com/topic/186471-download-counter/#findComment-985156 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.