Jump to content

Download Counter


DSGameMaker

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/186471-download-counter/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/186471-download-counter/#findComment-984812
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/186471-download-counter/#findComment-985145
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.