Can a view counter with an IP address use too much workload for MYSQL / PHP?

I am sure this is not a big problem for 10,000 MYSQL rows, but what if we have hundreds of thousands or even millions of rows?

Someone might tell me that cookies can solve the problem, but since I'm a newbie programmer, I believe that using cookies can cause more problems than solving problems.

Is there an alternative? Or should I stick with a non-IP sensitive counter? In my application, this counter is available only to the seller, and not to users, some of whom might want to play with the counter and update it many times. Therefore, if they do not see the counter, they will not play with refreshing.

Thanks in advance,

Hi

+1
source share
2 answers

IP addresses are integers.

Store them as integers and use the index in the corresponding column - queries will be very fast. Just keep in mind that ipv6 addresses are too large for 32-bit integers, so you may need to use varchar (16) instead and save the binary representations of your IP addresses.

Regarding the performance of your application, in my opinion, it is always useful to use some kind of caching system for this kind of statistics. For example, regenerate your statistics only if a certain period of time has passed.

+1
source

. item_id, ip_address . INSERT IGNORE -

CREATE TABLE `test`.`view_log` (
  `item_id` INTEGER UNSIGNED NOT NULL,
  `ip_address` INTEGER UNSIGNED NOT NULL,
  `date` DATE NOT NULL,
  PRIMARY KEY (`item_id`, `ip_address`, `date`)
);

INSERT IGNORE INTO view_log ($item_id, INET_ATON('$ip_address'), CURRENT_DATE);

. IPv4. IPv6 IP-.

+1

All Articles