Wednesday, 15 May 2013

php - Page hits counter - Am I overexerting the database? -


I have built a simple hit counter on my website. (PHP & MySQL, using CodeIgniter as my framework)

I use this table:

  table page_hits (id INT not NULL AUTO_INCREMENT , PAGE_URL VARCHAR (350) No NULL, IP VARCHAR (11) No NULL, INT not hit tap, `date` TIMESTAMP default CURRENT_TIMESTAMP tap, primary key (ID));  

On each page load, I check whether the page_url & amp; If there is a ip in the table, then I increase the value of 1 to hit 1. If not, then I will create a new line in the table. Timestamp is not to so as to does not hit much to refresh the page count as a new hit, allowing a certain delay between.

All this works well, but I am afraid that I can be overloaded in my database. .. In less than 24 hours, I have more than 6,500 lines in page_hits table

So my question is:. What are the risks of having such a fast growing table in my database? (? Duration of the database size exceeding performance issues?)

write me a line of SQL command again Do not start:

Default CURRENT_TIMESTAMP No NULL, Primary Key (ID))

Now I can see what's there

Your table is not complicated, but it's quick Areas will it will not be a problem, as long as you do not do anything with it. In other words: add rows in the table is no problem, even though as soon as you have one million rows

While you start query the table, you think it will be very slow You have forgotten to add index.

Secondly, you can think of getting rid of your table and getting rid of unnecessary information. For example, these three small tables:

  table page_hits (id INT no NULL AUTO_INCREMENT, page_id INT not NULL, client_id INT not NULL, INT no NULL kills, Primary key (ID) ) do not create tables pages (id INT NULL AUTO_INCREMENT, PAGE_URL VARCHAR (350) NULL, pRIMARY KEY (id)) table NULL not customers (id INT AUTO_INCREMENT, IP Create VARCHAR (11) nOT NULL, on TIMESTAMP NULL default CURRENT_TIMESTAMP, Primary key (id))  

indicates page_id here page Ndrbhit does table, and client_id > customer table, you must add indexes to myself to get rid of the date column, and a cookie With this problem will be resolved. Note that the new table can include more information without getting too large too quickly to be expanded.


No comments:

Post a Comment